当呼叫简单获取请求使用curl和Java Okhttp时,我得到了不同的结果
我使用curl在下面拨打下面的URL
curl 'http://username:[email protected]/merlin/Login.cgi'
,并且得到适当的响应,
{ "Session" : "0xb3e01810", "result" : { "message" : "OK", "num" : 200 } }
直接打开链接),邮递员甚至Nodejs获得相同的
响应
我会从浏览器( Okhttp是
Request request = new Request.Builder()
.url("http://username:[email protected]/merlin/Login.cgi")
.build();
try {
com.squareup.okhttp.Response response = client.newCall(request).execute();
System.out.println(response.code());
} catch (IOException e) {
e.printStackTrace();
}
I call below URL using cURL
curl 'http://username:[email protected]/merlin/Login.cgi'
and I get proper response
{ "Session" : "0xb3e01810", "result" : { "message" : "OK", "num" : 200 } }
I get the same response from browser (directly open link), postman and even with NodeJs,
but I get response code 401 when send GET_Request to this url using okhttp in java
my java code with okhttp is
Request request = new Request.Builder()
.url("http://username:[email protected]/merlin/Login.cgi")
.build();
try {
com.squareup.okhttp.Response response = client.newCall(request).execute();
System.out.println(response.code());
} catch (IOException e) {
e.printStackTrace();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用基本身份验证。在URL中具有用户名和密码,用
:
分开,与基本身份验证相同。我测试了,没关系。我的片段是:Use basic authentication. Having username and password in the url, separated with
:
, is the same as basic authentication. I tested and it's ok. my snippet is: