POST请求未发送数据-已修复

t00n

我已经在Android Studio中进行了很短的编程时间,并且一直试图以几种不同的方式(Retrofit2,Volley,HttpClient ...)将JSON发送到IIS服务器,但是我的IIS APP并没有做到正确在Mysql BBDD中不引入新行。

此方法来自我的IIS APP,该APP收到一个Json,将其转换为Object,然后对我的BBDD进行查询并引入新行。

 public String Post([FromBody] Empleado empleado)
    {}

该方法效果很好,因为我已经从IIS控制台应用程序中尝试了它,并且效果很好

我在Android Studio中所做的两个示例:

凌空抽射:

public class MainActivity extends AppCompatActivity {

TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    enviarDatos();
}

public void enviarDatos(){
    String url ="http://...myurl";
    textView = (TextView)findViewById(R.id.text);

    try {
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        final org.json.JSONObject jsonBody = new org.json.JSONObject();

        jsonBody.put("idTag",112353);
        jsonBody.put("Longitud","1253");
        jsonBody.put("Latitud","Test");

        JsonObjectRequest request = new JsonObjectRequest
                (Request.Method.POST, url, jsonBody, new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        textView.setText(response.toString());
                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // TODO Auto-generated method stub
                        textView.setText(error.toString());
                    }
                });

        requestQueue.add(request);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
}

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

任何帮助将不胜感激,感谢您的评论,对不起我的英语不好

编辑:终于可以了!好像我的URL端口出现了一些问题,所以我换了一下,它现在可以正常工作。

t00n

最后,它正在工作!好像我的URL端口出现了一些问题,因此我将其换成另一个,现在可以正常使用了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章