本文共 845 字,大约阅读时间需要 2 分钟。
我试着用代码制作http get request:
String username = "test\\v100";
String host = "1.2.3.4";
String password = "pass";
HttpClient client = new DefaultHttpClient();
AuthScope as = new AuthScope(host, 90);
UsernamePasswordCredentials upc = new UsernamePasswordCredentials(username, password);
((AbstractHttpClient) client).getCredentialsProvider().setCredentials(as, upc);
BasicHttpContext localContext = new BasicHttpContext();
BasicScheme basicAuth = new BasicScheme();
localContext.setAttribute("preemptive-auth", basicAuth);
HttpHost targetHost = new HttpHost(host, 90, "http");
HttpGet httpget = new HttpGet("/");
HttpResponse response = client.execute(targetHost, httpget, localContext);
但是在最后一行获得异常“java.net.SocketException:Permission denied”.
Android-2.2与eclipse IDE.
主机系统中的卷曲请求
curl -u test\v100:pass "http://1.2.3.4:90"
工作良好.
如何以正确的方式提出http请求?
谢谢!
转载地址:https://blog.csdn.net/weixin_34237125/article/details/114064350 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!