从android应用程序向服务器发送文本和pdf文件

从android应用程序向服务器发送文本和pdf文件,android,pdf,server,Android,Pdf,Server,当用户点击按钮时,我尝试向服务器发送一组编辑文本和PDF文件。我成功地单独发送了一组没有pdf的文本,然后我成功地发送了没有文本的pdf。我想在同一时间将它们发送到同一个url上如何做到这一点 文本代码 private class postData extends AsyncTask<String, Void, String> { // private final ProgressDialog dialog = ProgressDialog.show(get

当用户点击按钮时,我尝试向服务器发送一组编辑文本和PDF文件。我成功地单独发送了一组没有pdf的文本,然后我成功地发送了没有文本的pdf。我想在同一时间将它们发送到同一个url上如何做到这一点 文本代码

      private class postData extends AsyncTask<String, Void, String> {

      // private final ProgressDialog dialog = ProgressDialog.show(getActivity(), "",
     //       "Saving data to server. Please wait...", true);
    EditText email = (EditText) myView.findViewById(R.id.email);
    EditText phone = (EditText) myView.findViewById(R.id.email);
    String eemail=email.getText().toString();
    String pphone=phone.getText().toString();
    EditText first  = (EditText) myView.findViewById(R.id.firstname);
    EditText second= (EditText) myView.findViewById(R.id.lastname);
    String firstname=first.getText().toString();
    String lastname=second.getText().toString();

    @Override
    protected String doInBackground(String... params) {
        // perform long running operation operation

        // SharedPreferences settings = context.getSharedPreferences(PREFS_FILE, 0);
        //String server = settings.getString("server", "");
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://phone.tmsline.com/api/request_job");
        String json = "";
        String responseStr="";
        String result="true";


        try {
            // Add your data

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("email", eemail));
            nameValuePairs.add(new BasicNameValuePair("phone", pphone));
            nameValuePairs.add(new BasicNameValuePair("cv","not now"));
            nameValuePairs.add(new BasicNameValuePair("firstname", firstname));
            nameValuePairs.add(new BasicNameValuePair("lastname", lastname));

            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            try {
                httpclient.execute(httppost);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }



        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.i("HTTP Failed", e.toString());
        }
        return result;
    }
    protected void onPostExecute(String responseStr) {
        super.onPostExecute(responseStr);
        Toast.makeText(getActivity(),responseStr,Toast.LENGTH_LONG).show();

        if(responseStr.equals("true")){
            // Update your Button here
          Toast.makeText(getActivity(),"done finally",Toast.LENGTH_LONG).show();
        }

    }
}

与其使用所有这些,不如检查异步任务,您可以一起发送EditText数据PDF,否则您可以先发送EditText数据,然后在postExecute方法中发送PDF

public  void filetest(){
    String url = "http://phone.tmsline.com/api/";
    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),
            "Sherouk adel.pdf");
    try {
        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost(url);

        InputStreamEntity reqEntity = new InputStreamEntity(
                new FileInputStream(file), -1);
        reqEntity.setContentType("binary/octet-stream");
        reqEntity.setChunked(true); // Send in multiple parts if needed
        httppost.setEntity(reqEntity);
        //HttpResponse response = httpclient.execute(httppost);
        //Do something with response...

    } catch (Exception e) {
        // show error
    }