我试图使用Web浏览器项目的WebBrowser工具阻止Windows窗体应用程序C#中的网站。所以目前我能够阻止预定义的网站,但是,我希望能够添加到不可能的阵列。所以我想知道是否有另一种方式?
private void webBrowser1_Navigating(object sender,WebBrowserNavigatingEventArgs e)
{
String[] BlockList = new String[5]; //Array list stores the block list
BlockList[0] = "http://www.google.com";
BlockList[1] = "http://www.google.co.uk";
BlockList[2] = "http://www.gmail.com";
BlockList[3] = "http://www.yahoo.com";
BlockList[4] = "http://www.bing.com";
for (int i = 0; i < BlockList.Length; i++)
{
if (e.Url.Equals(BlockList[i]))
{
e.Cancel = true;
MessageBox.Show("Booyaa Says No!", "NO NO NO", MessageBoxButtons.OK, MessageBoxIcon.Hand); // Block List Error Message
}
}
}
答案 0 :(得分:2)
这是一个例子
public void method(){
try {
String apiKey = "AIzaSyB74usn5bPOiPi57DqC3mlaQHvIv5AEoWc";
//API key provided by Google Console
Usuario usuario = usuarioDao.findByTelefono("600112207");
String deviceID = usuario.getRegistrationId();
System.out.println(deviceID);
Content content = new Content();
//POJO class as above for standard message format
content.addRegId(deviceID);
content.createData("Mensaje para el usuario:",usuario.getUsuario());
URL url = new URL("https://android.googleapis.com/gcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "key="+apiKey);
conn.setDoOutput(true);
conn.setDoInput(true);
ObjectMapper mapper = new ObjectMapper();
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
mapper.writeValue(wr, content);
wr.flush();
wr.close();
inputStream = conn.getInputStream();
int responseCode = conn.getResponseCode();
} catch (IOException e) {
e.printStackTrace();
}
//the Content class
package antia.PFC.utils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class Content implements Serializable {
private static final long serialVersionUID = 4598819886093518574L;
public List<String> registration_ids;
public Map<String, String> data;
public void addRegId(String regId) {
if (registration_ids == null)
registration_ids = new LinkedList<String>();
registration_ids.add(regId);
}
public void createData(String title, String message) {
if (data == null)
data = new HashMap<String, String>();
data.put("title", title);
data.put("message", message);
}
}
//the service-worker.js
//Version 0.1
'use strict';
console.log('Started', self);
self.addEventListener('install', function(event) {
self.skipWaiting();
console.log('Installed', event);
});
self.addEventListener('activate', function(event) {
console.log('Activated', event);
});
self.addEventListener('push', function(event) {
console.log('Push message', event);
if (event.data) {
console.log('Push message',event.data.json())
}
var title = 'Mensaxe Quendas';
event.waitUntil(self.registration.showNotification(title,{
body : 'Ten vostede unha solicitude de cambio',
tag :'my-tag',
}));
});
然后你可以去
private List<string> BlockedUrls {get;set;}
private void webBrowser1_Navigating(object sender,WebBrowserNavigatingEventArgs e)
{
if(BlockedUrls.Contains(e.Url.ToString())
{
e.Cancel = true;
MessageBox.Show("Booyaa Says No!", "NO NO NO", MessageBoxButtons.OK, MessageBoxIcon.Hand); // Block List Error Message
}
}
}