安卓系统与asp.net网络服务的通信



我正试图将数据发布到asp.net web服务,但似乎不知道如何做到这一点。所以我需要发布像这样的数据

例如。http://yoors.somee.com/Default.aspx?type=EmailInsert&username=MYUSERNAME&password=MYPASS&name=MYNAME&电子邮件=MYEMAIL@PROVIDER.com&emailenabled=错误

之后,我得到了类似的JSON响应

{"VALID":"success"}

目前我正在使用这个函数,但它似乎不适用于这个目的。/

/ Create a new HttpClient and Post Header
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://yoors.somee.com/Default.aspx?type=EmailInsert");
                // http://yoors.somee.com/Default.aspx?type=Email
                // Insert&username=ben&password=pass&name=alv
                //&email=ben@yahoo.com&emailenabled=false
                try {
                    // Add your data
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                    nameValuePairs.add(new BasicNameValuePair("username",userName));
                    nameValuePairs.add(new BasicNameValuePair("name", name));
                    nameValuePairs.add(new BasicNameValuePair("password", password));
                    nameValuePairs.add(new BasicNameValuePair("email", email));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    // Execute HTTP Post Request
                    HttpResponse response = httpclient.execute(httppost);
                    Toast.makeText(Signup.this, response.getAllHeaders().toString(), Toast.LENGTH_LONG).show();
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                }

因此,任何人都可以指导我如何将数据发布到这个web服务

试试这个,但我不是asp.net专家:/

            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://yoors.somee.com/Default.aspx?type=EmailInsert");
            try {
                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("username",userName));
                nameValuePairs.add(new BasicNameValuePair("name", name));
                nameValuePairs.add(new BasicNameValuePair("password", password));
                nameValuePairs.add(new BasicNameValuePair("email", email));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);
                java.util.Scanner s = new java.util.Scanner(response.getEntity().getContent()).useDelimiter("\A");
                responseString = s.hasNext() ? s.next() : "";
                Log.d("Debug", responseString);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }

更新:

    HttpPost httppost = new HttpPost("http://yoors.somee.com/Default.aspx?type=EmailInsert&username=MYUSERNAME&password=MYPASS&name=MYNAME&email=MYEMAIL@PROVIDER.com&emailenabled=FALSE");

效果不错,但不是很好看。。。我想这里面有什么可找的!

最新更新