How to use parameters with HttpPost

后端 未结 3 478
借酒劲吻你
借酒劲吻你 2020-11-27 13:54

I am using a RESTfull webservice with this methode:

@POST
@Consumes({\"application/json\"})
@Path(\"create/\")
public void create(String str1, String str2){
         


        
3条回答
  •  再見小時候
    2020-11-27 14:42

    To set parameters to your HttpPostRequest you can use BasicNameValuePair, something like this :

        HttpClient httpclient;
        HttpPost httpPost;
        ArrayList postParameters;
        httpclient = new DefaultHttpClient();
        httpPost = new HttpPost("your login link");
    
    
        postParameters = new ArrayList();
        postParameters.add(new BasicNameValuePair("param1", "param1_value"));
        postParameters.add(new BasicNameValuePair("param2", "param2_value"));
    
        httpPost.setEntity(new UrlEncodedFormEntity(postParameters, "UTF-8"));
    
        HttpResponse response = httpclient.execute(httpPost);
    

提交回复
热议问题