Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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
使用补丁方法的androidrestapi_Android_Api_Rest - Fatal编程技术网

使用补丁方法的androidrestapi

使用补丁方法的androidrestapi,android,api,rest,Android,Api,Rest,在正常的post rest web服务中使用上述代码,它工作正常,但在补丁api中,它不工作,给出响应状态400意味着找不到页面,但在Chrome rest客户端中工作正常。 有补丁的解决方案吗?下载httpclient-4.2.jar文件 导入以下文件 import org.apache.http.message.AbstractHttpMessage; 导入org.apache.http.client.methods.HttpRequestBase; 导入org.apache.http.cl

在正常的post rest web服务中使用上述代码,它工作正常,但在补丁api中,它不工作,给出响应状态400意味着找不到页面,但在Chrome rest客户端中工作正常。
有补丁的解决方案吗?

下载httpclient-4.2.jar文件

导入以下文件

import org.apache.http.message.AbstractHttpMessage;
导入org.apache.http.client.methods.HttpRequestBase;
导入org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
导入org.apache.http.client.methods.HttpPatch;

HttpPatch请求=新的HttpPatch(strUrl)

代替

 HttpClient httpClient = new DefaultHttpClient(); 

    try {
        HttpPost request = new HttpPost(strUrl);

        StringEntity params =new StringEntity(json.toString(), "UTF-8");
        //request.addHeader("content-type", "application/x-www-form-urlencoded");
        params.setContentType("application/json");
        request.setEntity(params);
        HttpResponse response = httpClient.execute(request);

        HttpEntity entity1 = response.getEntity();
        is = entity1.getContent();
        int resopnceStatus = response.getStatusLine().getStatusCode();
        AppLog.logString(TAG + "get data resopnceStatus: " + resopnceStatus);

        if (resopnceStatus != 200) {
            return "Invalid";
        }
    }catch (IllegalArgumentException timeout) {
        timeout.printStackTrace();
        return "Invalid";
    } catch (SocketTimeoutException timeout) {
        timeout.printStackTrace();
        return "Invalid";
    } catch (Exception e) {
        e.printStackTrace();
        return "Invalid";
    }

    String response = "";
    String s = "";
    try {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
        while ((s = buffer.readLine()) != null) {
            response += s;
        }
    } catch (Exception e) {
        AppLog.logString(TAG + "get data Error in Buffered: " + e.toString());
        e.printStackTrace();
    }
    AppLog.logString(TAG + "get data Return Data is: " + response);

你能分享更多关于补丁api中的
的详细信息吗?它不工作了
@nikis what??它让我在android中出错,而在Chrome rest客户端中工作得很好。您谈论的是错误,但没有发布。@nikis它给出的响应代码400表示找不到页面,但这确实不是调用补丁方法的正确方式,但我不知道code
400
并不表示找不到页面,它表示请求不正确。您可以从比较从
Android
Chrome
发送的请求开始。
HttpPost request = new HttpPost(strUrl);