我要求我需要从Salesforce DB中获取数据。我的输入ID会超过1000+。因此,我想在post方法中传递此ID列表。
GET方法失败,因为它超出了限制。
有人可以帮我吗?
我从您的问题中假设,对SalesForce的一些(但不是全部)GET请求已经在工作,因此您已经拥有与SalesForce对话所需的大部分代码,而您只需要填补如何发出POST请求的空白即可GET请求。
我希望下面的代码对此有所说明。请注意,它未经测试,因为我目前没有访问SalesForce实例来针对它进行测试:
import org.apache.http.HttpHeaders;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.message.BasicNameValuePair;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
public class HttpPostDemo {
public static void main(String[] args) throws Exception {
String url = ... // TODO provide this.
HttpPost httpPost = new HttpPost(url);
// Add the header Content-Type: application/x-www-form-urlencoded; charset=UTF-8.
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.withCharset(StandardCharsets.UTF_8).getMimeType());
// Construct the POST data.
List<NameValuePair> postData = new ArrayList<>();
postData.add(new BasicNameValuePair("example_key", "example_value"));
// add further keys and values, the one above is only an example.
// Set the POST data in the HTTP request.
httpPost.setEntity(new UrlEncodedFormEntity(postData, StandardCharsets.UTF_8));
// TODO make the request...
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句