Android:如何使用HttpPut请求发送内容
我正在开发一个应用程序,希望通过HttpPut请求发送内容。 我正在将其发送到远程服务器,但无法识别。 我正在将请求发送到RESTAPI 这是我的密码:Android:如何使用HttpPut请求发送内容,android,Android,我正在开发一个应用程序,希望通过HttpPut请求发送内容。 我正在将其发送到远程服务器,但无法识别。 我正在将请求发送到RESTAPI 这是我的密码: HttpURLConnection connection; try{ URL url = new URL(Constants.url_domain+"listings/"+idvalue); //URL url = new URL(imageUrl); HttpPut httpRequest = null; ht
HttpURLConnection connection;
try{
URL url = new URL(Constants.url_domain+"listings/"+idvalue);
//URL url = new URL(imageUrl);
HttpPut httpRequest = null;
httpRequest = new HttpPut(url.toURI());
String basicAuth = "Basic " + new String(Base64.encode("username:password123#".getBytes(),Base64.NO_WRAP ));
httpRequest.setHeader("Authorization", basicAuth);
MultipartEntity entity2 = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity2.addPart("title",new StringBody(titlevalue));
entity2.addPart("price",new StringBody(pricevalue));
entity2.addPart("active",new StringBody("false"));
httpRequest.setEntity(entity2);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
}
服务器响应了什么?还是根本没有响应?谢谢您的响应。没有服务器响应,但响应错误,我希望active=false,但我正在变得active=true。这意味着服务器没有正确响应我的请求。通过Poster插件,我可以从服务器发送并获得正确的响应,但上面的代码不起作用:(你试过这种方法吗