Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:如何使用HttpPut请求发送内容_Android - Fatal编程技术网

Android:如何使用HttpPut请求发送内容

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

我正在开发一个应用程序,希望通过HttpPut请求发送内容。 我正在将其发送到远程服务器,但无法识别。 我正在将请求发送到RESTAPI

这是我的密码:

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插件,我可以从服务器发送并获得正确的响应,但上面的代码不起作用:(你试过这种方法吗