gpt4 book ai didi

java - java 中的 httpurlConnection 与 httpParams

转载 作者:太空宇宙 更新时间:2023-11-04 12:55:04 25 4
gpt4 key购买 nike

我正在尝试通过交换机将文件从本地发布到另一个平台。当我使用 DefaultHttpClient 执行此操作时,没有问题。

HttpParams params = new BasicHttpParams();
params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, InetAddress.getByName(interfaceIp));
DefaultHttpClient httpClientPost = new DefaultHttpClient(params);

但我必须使用 HttpURLConnection 来做到这一点。有办法做到这一点吗?

例如:

httpConn = (HttpURLConnection) url.openConnection(myHttpParams);

这是我的 HttpUrlConn 代码

            url = new URL(baseUrl+"/html/uploadimage.cgi");
httpConn = (HttpURLConnection) url.openConnection();
httpConn.setUseCaches(false);
httpConn.setDoOutput(true); // indicates POST method
httpConn.setDoInput(true);
httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" +"----WebKitFormBoundary"+boundary);
httpConn.setRequestProperty("Host", "192.168.1.1");
httpConn.setRequestProperty("Connection", "keep-alive");
httpConn.setRequestProperty("Content-Length", "16551361");
httpConn.setRequestProperty("Cache-Control", "max-age=0");
httpConn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
httpConn.setRequestProperty("Origin", "http://192.168.1.1");
httpConn.setRequestProperty("Upgrade-Insecure-Requests", "1");
httpConn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
httpConn.setRequestProperty("Referer", baseUrl + "/html/advance.html");
httpConn.setRequestProperty("Accept-Encoding", "gzip, deflate");
httpConn.setRequestProperty("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.6,en;q=0.4");

String cookie = "Username="+ username +"; " +
"Password="+ cyreptedPassword +"; Language=tk; " +
"username="+ username +"; " +
"SessionID_R3="+ sessionID +"; activeMenuID=maintain_settings; activeSubmenuID=device_mngt";

httpConn.setRequestProperty("Cookie", cookie);
httpConn.setAllowUserInteraction(true);
httpConn.setConnectTimeout(9999*9999999);
outputStream = httpConn.getOutputStream();
writer = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8"), true);

谢谢大家。

最佳答案

HttpUrlConnection 不使用 http 参数,但它使用代理。

here是有关 httpUrlConnection 示例的一些信息。

关于java - java 中的 httpurlConnection 与 httpParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35478056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com