使用MultipartEntityBuilder后如何查看完整的URL?

时间:2015-02-11 11:40:30

标签: java php android http-post multipartentity

我相信这段代码是有效的(我在项目的另一部分用于不同的API)就发布而言我不认为URL格式正确。我想知道在构建所有实体之后是否还有查看完整的URL,以便我可以看到最终的URL是否格式正确。代码:

我的网址= http://pillbox.nlm.nih.gov/PHP/pillboxAPIService.php 方法= POST

API密钥=不会发布(虽然有效)

drugName =只是一个名为药物的字符串

我已在代码中登录以尝试查看网址,但他们不会返回任何内容并且调试器也不是。

我正在尝试构建如下所示的URL: http://pillbox.nlm.nih.gov/PHP/pillboxAPIService.php?key=My_API_KEY&ingredient=diovan

public String makeServiceCallPillBox(String url, int method, 
        String api, String drugName) 
{
    String resultEnitity = null; 
    try {
        // http client
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpResponse httpResponse = null;
        HttpEntity entityResult = null;



        // Checking http request method type
        if (method == POST) 
        {
            HttpPost httpPost = new HttpPost(url);
            // Butild the parameters
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); 
            builder.addTextBody("key", api);
            builder.addTextBody("ingredient", drugName);; 
            final HttpEntity entity = builder.build();
            httpPost.setEntity(entity);
            Log.d("url", httpPost.toString());
            httpResponse = httpClient.execute(httpPost);

            Log.d("post", builder.toString());
            Log.d("post2", entity.toString()); 

            entityResult = httpResponse.getEntity();

            resultEnitity = EntityUtils.toString(entityResult);

            Log.d("result", resultEnitity);

        }   

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return resultEnitity;

}

感谢任何帮助。

0 个答案:

没有答案