0

我正在尝试将数据发布到 asp.net Web 服务,但似乎我不知道该怎么做。所以我需要发布这样的数据

例如。http://yoors.somee.com/Default.aspx?type=EmailInsert&username=MYUSERNAME&password=MYPASS&name=MYNAME&email=MYEMAIL@PROVIDER.com&emailenabled=FALSE

之后我得到这样的 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
                }

那么任何人都可以指导我如何将数据发布到这个网络服务

4

1 回答 1

0

试试这个,但我不是 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");

工作正常,但它不是很漂亮......我认为有一些东西可以找到!

于 2013-07-25T10:30:39.523 回答