使用android发送json对象不会';行不通

使用android发送json对象不会';行不通,android,json,httpclient,Android,Json,Httpclient,我想将json对象发送到我的Web服务并读取响应,但我的代码不起作用。已创建JSON对象,但可能未发送。WebService未收到此对象 我的活动: package com.example.secapp; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.Menu; im

我想将json对象发送到我的Web服务并读取响应,但我的代码不起作用。已创建JSON对象,但可能未发送。WebService未收到此对象

我的活动:

package com.example.secapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.*;
import java.io.InputStream;





public class dwa extends Activity {


    Context context;


    TextView imie;
    TextView wiek;
    Button przycisk;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wynik);
        context = getApplicationContext();

        Bundle bundle = getIntent().getExtras();
        String URL = "http://192.168.0.105:8080/2WS/test/login";
        JSONObject json = new JSONObject();
        HttpResponse response;
        HttpClient client = new DefaultHttpClient();

        try {
            json.put("login",bundle.getString("login") );
            json.put("password",bundle.getString("pass") );
            System.out.println(json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }


        try {
            HttpPost post = new HttpPost(URL);
            StringEntity se = new StringEntity( json.toString());
            post.setHeader("Accept", "application/json");
            post.setEntity(se);
            response = client.execute(post);
            if(response!=null){
                InputStream in = response.getEntity().getContent();
            }

        } catch(Exception e) {
            e.printStackTrace();
        }

        imie = (TextView) findViewById(R.id.textView3);
        wiek = (TextView) findViewById(R.id.textView5);



        String imieString = bundle.getString("login");
        String wiekString = bundle.getString("pass");


        imie.setText(imieString);
        wiek.setText(wiekString);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

谢谢你的帮助,对不起我的英语

如果要在应用程序中集成api,请使用改型:square.github.io/refundation/


希望能有帮助

请尝试从web浏览器发出请求,并查看web服务是否正在响应。是的,web服务正在工作并正在响应。从设备上的浏览器发出请求如何?问题可能在于获得到该地址的连接,而不是代码有任何问题。