Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android:在向服务器发布图像时如何添加edittext值_Java_Android_Android Edittext - Fatal编程技术网

Java android:在向服务器发布图像时如何添加edittext值

Java android:在向服务器发布图像时如何添加edittext值,java,android,android-edittext,Java,Android,Android Edittext,我是android开发的新手… 我发现这段将图像上传到服务器的代码及其工作非常完美… 只需在布局中添加edittext,我也希望将带有图像的edittext的值发布到服务器 我的部分代码: URL url = new URL(upLoadServerUri); conn = (HttpURLConnection) url.openConnection(); // Open a HTTP connection to the URL conn.setDoIn

我是android开发的新手…
我发现这段将图像上传到服务器的代码及其工作非常完美…
只需在布局中添加edittext,我也希望将带有图像的edittext的值发布到服务器
我的部分代码:

 URL url = new URL(upLoadServerUri);
         conn = (HttpURLConnection) url.openConnection(); // Open a HTTP  connection to  the URL
         conn.setDoInput(true); // Allow Inputs
         conn.setDoOutput(true); // Allow Outputs
         conn.setUseCaches(false); // Don't use a Cached Copy
         conn.setRequestMethod("POST");
         conn.setRequestProperty("Connection", "Keep-Alive");
         conn.setRequestProperty("ENCTYPE", "multipart/form-data");
         conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
         conn.setRequestProperty("uploaded_file", fileName);
         dos = new DataOutputStream(conn.getOutputStream());

         dos.writeBytes(twoHyphens + boundary + lineEnd);
         dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""+ fileName + "\"" + lineEnd);
         dos.writeBytes(lineEnd);

         bytesAvailable = fileInputStream.available(); // create a buffer of  maximum size

         bufferSize = Math.min(bytesAvailable, maxBufferSize);
         buffer = new byte[bufferSize];

         // read file and write it into form...
         bytesRead = fileInputStream.read(buffer, 0, bufferSize); 

         while (bytesRead > 0) {
           dos.write(buffer, 0, bufferSize);
           bytesAvailable = fileInputStream.available();
           bufferSize = Math.min(bytesAvailable, maxBufferSize);
           bytesRead = fileInputStream.read(buffer, 0, bufferSize);              
          }

         // send multipart form data necesssary after file data...
         dos.writeBytes(lineEnd);
         dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

         // Responses from the server (code and message)
         int serverResponseCode = conn.getResponseCode();
         //String serverResponseMessage = conn.getResponseMessage();
         if(serverResponseCode == 200){
             runOnUiThread(new Runnable() {
                  public void run() {
我的编辑文本:

<EditText
    android:id="@+id/detail"
    android:layout_width="match_parent"
    android:layout_height="164dp"
    android:layout_gravity="right"
    android:layout_marginBottom="15dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:ems="10"
    android:hint="About Your picture"
    android:inputType="textMultiLine" >

任何人都可以用我的代码添加示例,说明我如何在此EditText中获取值并将其添加到表单中
要发布此edittext的图像和值?

而不是此

conn.setRequestProperty("firstName", "Stephen");
你必须使用

conn.setRequestProperty("firstName", urDetailEdtTxt.getText().toString());

对于这种
post请求
u需要一个键值对如果键是
firstName
,那么它将以其他方式工作,用正确的键替换键。

我找到conn.setRequestProperty(“firstName”,“Stephen”);在这个网站-它是解决我的问题的工作?