0

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

这是我的代码:

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);
}
4

0 回答 0