简体   繁体   English

使用Java将发布请求发送到Salesforce

[英]Send post request to salesforce in java

I have requirement that I need to fetch the data form salesforce DB. 我要求我需要从Salesforce DB中获取数据。 My input Ids would be more than 1000+. 我的输入ID将超过1000+。 Hence I would like to pass this list of Ids in post method. 因此,我想在post方法中传递此ID列表。

GET method is failing since it exceeds the limit. GET方法失败,因为它超出了限制。

Can someone help me on this? 有人可以帮我吗?

I'm assuming from your question that some (but not all) GET requests to SalesForce are already working, so you already have most of the code needed to talk to SalesForce and you just need the gaps filling on how to make a POST request instead of a GET request. 我从您的问题中假设,对SalesForce的某些(但不是全部)GET请求已经在工作,因此您已经拥有与SalesForce对话所需的大部分代码,而您只需要填补如何发出POST请求的空白即可。 GET请求。

I hope the following code provides some demonstration of this. 我希望下面的代码对此进行一些演示。 Note that it is untested as I don't presently have access to a SalesForce instance to test it against: 请注意,它未经测试,因为我目前没有访问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...
    }
}

It is perhaps worth pointing out that in essence the code isn't much different to that in a related question which appears in the sidebar. 可能值得指出的是,从本质上讲,该代码侧栏中出现的相关问题的代码没有太大不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM