gpt4 book ai didi

android - 客户端协议(protocol)异常

转载 作者:行者123 更新时间:2023-11-29 18:18:07 25 4
gpt4 key购买 nike

我想在我的应用程序中使用 RESTFul 网络服务。

PUT /API/Authentication HTTP/1.1 
HOST: $baseuri:port
Accept: text/xml
Content-Type: text/xml;
charset=utf-8
Content-Length: nnnn

<?xml version="1.0" encoding="utf-8"?>
<Myapp xmlns="http://schemas.myapp.com/REST/Requests/05172011/SignIn">
<SignInRequest>
<UID>ME</UID>
<PWD>BlackPearl</PWD>
</SignInRequest>
</Myapp>

我试过一些代码。但它显示 ClientProtocolException。我的代码有什么错误?请帮我。谢谢...

  String auth="myname:mypassword";
String encoded_auth=Base64.encodeToString(auth.getBytes(),Base64.DEFAULT);
String auth_header= "Authorization: BASIC "+encoded_auth;

String xml="<?xml version='1.0' encoding='utf-8'?><Myapp xmlns='http://schemas.myapp.com/REST/Requests/05202011/SignIn'><SignInRequest><UID>ME</UID><PWD>BlackPearl</PWD></SignInRequest></Myapp>";
int l=xml.length();

StringEntity e = new StringEntity(xml);
e.setContentType("text/xml");
e.setContentEncoding("UTF-8");

HttpPut objPut = new HttpPut(basruri+"/myApp/API/Authentication");
objPut.setHeader("Content-Type","text/xml;charset=utf-8");
objPut.setHeader("Accept","text/xml");
objPut.setHeader("Host",basruri);
objPut.setHeader("Content-Length",Integer.toString(l));
objPut.setHeader("Authorization",auth_header);
objPut.setEntity(e);

DefaultHttpClient objClient = new DefaultHttpClient();
ResponseHandler objResponse = new BasicResponseHandler();

HttpResponse s=objClient.execute(objPut);

最佳答案

尝试删除 Host 和 Content-Length header ,它对我有用。

关于android - 客户端协议(protocol)异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7105649/

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