繁体   English   中英

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

[英]Send post request to salesforce in java

我要求我需要从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...
    }
}

可能值得指出的是,从本质上讲,该代码侧栏中出现的相关问题的代码没有太大不同。

暂无
暂无

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

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