httpclient poset get 发送请求和curl对应参数

在网上查了很多资料,感觉没有头绪。在拼接发送报文的方法有很多种

 HttpClient httpclient = new HttpClient();
   GetMethod gm = new GetMethod(serviceUrl);//实例化get方法,并传递要请求的url。如果不传入的话,会报空指针错误
    
   //set the token in the header
   gm.setRequestHeader("Authorization", "Bearer "+accessToken);//设置发送请求的报头。
  
   //set the SOQL as a query param
   NameValuePair[] params = new NameValuePair[1];
       
   /**
    * other option instead of query string, pass just the fields you want back:
    *  https://instance_name.salesforce.com/services/data/v20.0/sobjects/Account/
    *       001D000000INjVe?fields=AccountNumber,BillingPostalCode
    */
   params[0] = new NameValuePair("q","SELECT name, title FROM Contact LIMIT 100");
   gm.setQueryString(params); //以上代码就是拼接一个query串,例如 ?a = a&b = b 这部分代码有很多实现方式。一下会慢慢总结。
   
   httpclient.executeMethod(gm);//执行方法
   String responseBody = gm.getResponseBodyAsString();//获取相应的结果,大部分为json串
   //解析json字符串


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值