将名称值对附加到另一个名称值对

发布于 2024-12-21 10:16:25 字数 866 浏览 5 评论 0原文

这是调用方法的代码 -

NameValuePair[] data = {
        new NameValuePair("first_name", firstName),
        new NameValuePair("last_name", lastName),
        new NameValuePair("email", email),
        new NameValuePair("company", organization),
        new NameValuePair("phone", phone)
    };
    SalesForceFormSubmissionUtil.submitForm(data,CONTACT_FOR_TYPE);

在被调用的方法中 -

  public static void submitForm(NameValuePair[] givendata, String contactType) {
    HttpClient client = new HttpClient();
    PostMethod post = new PostMethod(Constants.SALESFORCE_URL);
    NameValuePair[] data = {
        new NameValuePair("oid", Constants.SALESFORCE_OID),
        new NameValuePair(Constants.SALESFORCE_CAMPAIGN_ID, contactType)
    };
    post.setRequestBody(data);

我想添加给定的数据和数据并将其作为 post 请求发送。你们能建议我如何附加两者吗?

here is the code of the calling method -

NameValuePair[] data = {
        new NameValuePair("first_name", firstName),
        new NameValuePair("last_name", lastName),
        new NameValuePair("email", email),
        new NameValuePair("company", organization),
        new NameValuePair("phone", phone)
    };
    SalesForceFormSubmissionUtil.submitForm(data,CONTACT_FOR_TYPE);

In the called method -

  public static void submitForm(NameValuePair[] givendata, String contactType) {
    HttpClient client = new HttpClient();
    PostMethod post = new PostMethod(Constants.SALESFORCE_URL);
    NameValuePair[] data = {
        new NameValuePair("oid", Constants.SALESFORCE_OID),
        new NameValuePair(Constants.SALESFORCE_CAMPAIGN_ID, contactType)
    };
    post.setRequestBody(data);

i want to add both the givendata & data and send it as a post request. Can you guys suggest me how to append both.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠栀 2024-12-28 10:16:25

如果您只想合并两个数组,可以创建第三个数组 (combinedData),其大小为 givenData.length + data.length ,那么您必须从源数组中复制元素。

不过,还有很多其他方法可以解决这个问题,例如:下面是使用 ArrayList 作为中间人/助手的实现。

String[] A1 = {"hello","world"};
String[] A2 = {"I","am","bored"};

...

ArrayList<String> temp = new ArrayList<String> (A1.length + A2.length);

temp.addAll (Arrays.asList (A1));
temp.addAll (Arrays.asList (A2));

String[] A3 = temp.toArray (new String[temp.size ()]);

...

for (int i=0; i < A3.length; ++i)
  System.out.println (A3[i]);

输出

hello
world
I
am
bored

If you just want to combine the two arrays you can create a third array (combinedData) with a size of givenData.length + data.length, then you'll have to copy the elements from your source arrays.

Though, there are plenty of other methods to solve this, as an example; below is an implementation using a ArrayList as a middle-man/helper.

String[] A1 = {"hello","world"};
String[] A2 = {"I","am","bored"};

...

ArrayList<String> temp = new ArrayList<String> (A1.length + A2.length);

temp.addAll (Arrays.asList (A1));
temp.addAll (Arrays.asList (A2));

String[] A3 = temp.toArray (new String[temp.size ()]);

...

for (int i=0; i < A3.length; ++i)
  System.out.println (A3[i]);

output

hello
world
I
am
bored
℉絮湮 2024-12-28 10:16:25
public static void submitForm(NameValuePair[] givendata, String contactType) {
   HttpClient client = new HttpClient();
   PostMethod post = new PostMethod(Constants.SALESFORCE_URL);
   post.setRequestBody(givendata);
   post.addParameters({
      new NameValuePair("oid", Constants.SALESFORCE_OID),
      new NameValuePair(Constants.SALESFORCE_CAMPAIGN_ID, contactType)
   });
   ...
public static void submitForm(NameValuePair[] givendata, String contactType) {
   HttpClient client = new HttpClient();
   PostMethod post = new PostMethod(Constants.SALESFORCE_URL);
   post.setRequestBody(givendata);
   post.addParameters({
      new NameValuePair("oid", Constants.SALESFORCE_OID),
      new NameValuePair(Constants.SALESFORCE_CAMPAIGN_ID, contactType)
   });
   ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文