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);

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

4

2 回答 2

0

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

但是,作为示例,还有很多其他方法可以解决此问题;下面是使用 aArrayList作为中间人/助手的实现。

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
于 2011-12-16T08:14:36.140 回答
0
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)
   });
   ...
于 2011-12-16T08:47:46.010 回答