通过代理访问一些网址

import java.io.IOException;
import java.io.InputStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.Properties;

public class HttpProxy {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Properties prop = System.getProperties();
prop.put("proxySet","true");
// 设置http访问要使用的代理服务器的地址
prop.setProperty("http.proxyHost", "130.194.11.121");
// 设置http访问要使用的代理服务器的端口
prop.setProperty("http.proxyPort", "1080");
prop.list(System.out);
// 设置不需要通过代理服务器访问的主机,可以使用*通配符,多个地址用|分隔
//prop.setProperty("http.nonProxyHosts", "localhost|192.168.0.*");
// 设置安全访问使用的代理服务器地址与端口
// 它没有https.nonProxyHosts属性,它按照http.nonProxyHosts 中设置的规则访问
/*
prop.setProperty("https.proxyHost", "192.168.0.254");
prop.setProperty("https.proxyPort", "443");
*/
// 使用ftp代理服务器的主机、端口以及不需要使用ftp代理服务器的主机
/*
prop.setProperty("ftp.proxyHost", "192.168.0.254");
prop.setProperty("ftp.proxyPort", "2121");
prop.setProperty("ftp.nonProxyHosts", "localhost|192.168.0.*");
*/
// socks代理服务器的地址与端口
/*
prop.setProperty("socksProxyHost", "192.168.0.254");
prop.setProperty("socksProxyPort", "8000");
*/
// 设置登陆到代理服务器的用户名和密码
Authenticator.setDefault(new MyAuthenticator("", ""));
URL url;
HttpURLConnection http;
InputStream urlstream;
try {
url = new URL("http://www.blogger.com/");
http = (HttpURLConnection)url.openConnection();
http.connect();
urlstream = http.getInputStream();
byte buffer[] = new byte[1024];
int i;
while ((i =urlstream.read(buffer)) != -1) {
System.out.write(buffer, 0, i);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
vector<CString> vecList; vecList.push_back(_T("110.77.0.3:80 ")); vecList.push_back(_T("106.60.94.127:80 ")); vecList.push_back(_T("49.94.32.45:80 ")); vecList.push_back(_T("119.188.94.145:80 ")); vecList.push_back(_T("37.49.137.243:80 ")); vecList.push_back(_T("111.13.132.92:80 ")); vecList.push_back(_T("49.94.148.119:80 ")); vecList.push_back(_T("49.94.164.209:80 ")); vecList.push_back(_T("49.94.2.84:80 ")); vecList.push_back(_T("49.90.1.251:80 ")); vecList.push_back(_T("117.37.243.194:80 ")); vecList.push_back(_T("110.4.12.175:80 ")); vecList.push_back(_T("36.98.30.234:80 ")); vecList.push_back(_T("110.244.111.56:80 ")); vecList.push_back(_T("49.94.131.174:80 ")); vecList.push_back(_T("111.1.61.23:80 ")); vecList.push_back(_T("54.252.97.45:80 ")); vecList.push_back(_T("111.13.12.202:80 ")); vecList.push_back(_T("106.33.2.219:80 ")); vecList.push_back(_T("110.176.86.5:80 ")); vecList.push_back(_T("171.9.147.106:80 ")); vecList.push_back(_T("200.33.27.33:80 ")); vecList.push_back(_T("49.94.141.104:80 ")); vecList.push_back(_T("110.176.178.131:80 ")); vecList.push_back(_T("49.93.24.73:80 ")); vecList.push_back(_T("111.12.128.166:80 ")); vecList.push_back(_T("223.15.233.54:80 ")); vecList.push_back(_T("123.173.206.192:80 ")); vecList.push_back(_T("110.77.197.132:80 ")); vecList.push_back(_T("49.94.0.196:80 ")); WebClient wc; WebClient wc2; CString strData=_T(""); for(int i=0;i<vecList.size();i++) { try { CString str1; CString strIP=vecList[i]; strIP.Trim(); wc.SetProxy(strIP); CString strTemp=_T(""); wc.Get(_T("http://www.2345.com/?24384-1217"),strTemp); str1.Format(_T("%s ->%s\r\n"),strIP,strTemp); strData+=str1; wc2.SetProxy(strIP); wc.Get(_T("http://www.haosooo.cn/?f=me"),strTemp); str1.Format(_T("%s ->%s\r\n"),strIP,strTemp); CSuperLog::WriteLog(str1); Sleep((1000)); } catch (...) { } }
在Unity中,由于安全原因和避免直接在游戏内打开浏览器,通常不会直接让应用程序访问外部网址。然而,如果你需要从Unity游戏中获取数据或者进行一些交互,你可以使用以下几种间接的方式来实现: 1. JSON Web Services (RESTful APIs): 创建或使用公共API,通过发送HTTP请求获取你需要的信息。Unity提供了HttpModule或第三方插件如uNetworking,来进行网络请求。 ```csharp WWW www = new WWW("http://example.com/api/data"); while (!www.isDone) { // 等待请求完成 } string jsonData = www.text; ``` 2. UnityWebRequest: 如果你想更现代一些,可以使用Unity自带的UnityWebRequest组件。 ```csharp using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.Net; public class ExternalWebsite : MonoBehaviour { public Button button; private UnityWebRequest request; void Start() { button.onClick.AddListener(RunRequest); } void RunRequest() { request = UnityWebRequest.Get("https://example.com"); StartCoroutine(DownloadWebpage()); } IEnumerator DownloadWebpage() { yield return request.SendWebRequest(); if(request.isNetworkError || request.isHttpError) Debug.LogError("Failed to download webpage: " + request.error); else { string responseText = request.downloadHandler.text; // 处理响应数据 } } } ``` 3. 服务端代理: 你可以设置一个服务器作为桥梁,将游戏内的请求转发到外部网站处理,然后返回结果给游戏。 注意,上述方法大多用于获取数据而不是引导用户直接跳转到其他网站。在实际项目中,你可能会选择提供某种用户界面元素(比如一个链接),当用户点击时,提示他们离开游戏或打开新的应用处理外部链接。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值