我正在使用此代码,但我无法发送字符串数组:
httpclIEnt = new DefaulthttpClIEnt();httppost = new httpPost(Call_Server.UPLOAD_VIDEO);multipartentity mpEntity = new multipartentity( httpMultipartMode.STRICT);mpEntity.addPart("file_UPLOAD", new fileBody(vIDeofile));mpEntity.addPart("from_email", new StringBody( Call_Server.useremail));mpEntity.addPart("recipIEnt_emails", new StringBody( AddressArray));httppost.setEntity(mpEntity);httpResponse response = httpclIEnt.execute(httppost);httpentity resEntity = response.getEntity();
解决方法:
你可以做这样的事情.
// Prepare category Arrayfor (String mBusinessID : mSelectedcategoryArray) { reqEntity.addPart("categoryCBG[]", new StringBody(mBusinessID));}
只需在数组中添加[]数组标记和paas值.
这里categoryCBG是数组标签.您可以使用循环传递此标记中的值.它将作为一个数组发布在服务器上.
以下是我使用它的完整代码:
public String executeMultipartPost() throws Exception { try { ByteArrayOutputStream mByteOutputStream = new ByteArrayOutputStream(); mSelectedImage.compress(CompressFormat.JPEG, 75, mByteOutputStream); byte[] mImageByteDate = mByteOutputStream.toByteArray(); httpClIEnt httpClIEnt = new DefaulthttpClIEnt(); httpPost postRequest = new httpPost(CONSTANTS.MAIN_URL_GLOBAL + CONSTANTS.BUSInesS_REGISTRATION_TAG); ByteArrayBody mImageByteArray = new ByteArrayBody(mImageByteDate, Long.toString(System.currentTimeMillis()) + ".jpg"); multipartentity reqEntity = new multipartentity(httpMultipartMode.broWSER_COMPATIBLE); reqEntity.addPart("logo_img", mImageByteArray); reqEntity.addPart("name", new StringBody(txtBusinessname_business_registration.getText().toString())); reqEntity.addPart("email", new StringBody(txtBusinessEmail_business_registration.getText().toString())); reqEntity.addPart("contact_phone", new StringBody(txtBusinessPhone_business_registration.getText().toString())); reqEntity.addPart("link_url", new StringBody(txtBusinessWebsite_business_registration.getText().toString())); reqEntity.addPart("Address", new StringBody(txtStreetAddress_business_registration.getText().toString())); reqEntity.addPart("City", new StringBody(txtCity_business_registration.getText().toString())); reqEntity.addPart("State", new StringBody(txtState_business_registration.getText().toString())); reqEntity.addPart("Zip", new StringBody(txtZip_business_registration.getText().toString())); reqEntity.addPart("details", new StringBody(txtDetail_business_registration.getText().toString())); reqEntity.addPart("products", new StringBody(txtService_business_registration.getText().toString())); // Prepare category Array for (String mBusinessID : mSelectedcategoryArray) { reqEntity.addPart("categoryCBG[]", new StringBody(mBusinessID)); } postRequest.setEntity(reqEntity); httpResponse response = httpClIEnt.execute(postRequest); BufferedReader reader = new BufferedReader(new inputStreamReader(response.getEntity().getContent(), "UTF-8")); String sResponse; mStringBuilder = new StringBuilder(); while ((sResponse = reader.readline()) != null) { mStringBuilder = mStringBuilder.append(sResponse); } return mStringBuilder.toString(); } catch (Exception e) { e.printstacktrace(); // handle exception here Log.e(e.getClass().getname(), e.getMessage()); return "error"; } }
更新
要取消ongioing上传,您可以使用
httpClIEnt.getConnectionManager().shutdown();
总结 以上是内存溢出为你收集整理的如何使用post方法将一个关键字中的字符串数组值发送到服务器全部内容,希望文章能够帮你解决如何使用post方法将一个关键字中的字符串数组值发送到服务器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)