通过服务器发送图像的安卓应用程序:wamp


Android app to send image over server : wamp

我想构建一个Android应用程序来通过服务器发送图像数据。首先,我想将文本数据从我的应用程序发送到我机器上的本地主机。我正在使用 WAMP 服务器。

我已经在 eclipse 上编写了这段代码,并在 C:/wamp/www/文件夹上创建了 mypage.php

package com.example.httpexample;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://localhost/mypage.php");
        try {
             List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
             nameValuePairs.add(new BasicNameValuePair("fname", "vinod"));
             nameValuePairs.add(new BasicNameValuePair("fphone", "1234567890"));
             nameValuePairs.add(new BasicNameValuePair("femail", "abc@gmail.com"));
             nameValuePairs.add(new BasicNameValuePair("fcomment", "Help"));
             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
             httpclient.execute(httppost);
         } catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
         } catch (IOException e) {
             // TODO Auto-generated catch block
         }
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

但是当我运行模拟器时,我看不到数据从模拟器发送到本地主机上的 mytest.php 文件。

我是这个领域的新手,可能没有做对一些事情。请提出出路。如果您愿意,请向我询问更多详细信息。另外我想告诉我的研究所使用代理服务器(但由于我连接到我的机器应该不是问题)。

使用多部分实体上传服务器上的图像数据或上传图像的本地链接上传图像,并按照此链接连接本地主机。

相关文章: