1

我正在和我的朋友一起做我的 android 项目,我们在某个时候卡住了。我正在尝试向 WCF REST Web 服务发布异步帖子,在服务端,我将数据插入到数据库中。我通过 JSON 对象发送数据。我打开一个对话框,请求成功完成后,对话框消失。现在我的问题是,我无法发出发布请求,实际上,我没有收到任何错误,但似乎有问题。获取请求没有问题。我要疯了,所以我需要你的帮助。这是我的代码

谢谢

JAVA

        progressDialog = ProgressDialog.show(Activity3.this, "Please wait ...",  "Task in progress ...", true);
        progressDialog.setCancelable(true);
        jarray = new JSONArray();
        json2 = new JSONObject();

        AsyncHttpClient client = new AsyncHttpClient();
        try {

            json2.put("CreateDate", "30.03.2014 15:30:00");
            json2.put("EventCategory", "Yemek");
            json2.put("EventID", "6");
            json2.put("EventName", "Kanatçı Haydar");
            json2.put("EventStatus", "A");
            json2.put("FsqID", "561239");
            json2.put("IsPublic", "False");
            json2.put("LastUpdate", "01.01.0001 00:00:00");
            json2.put("Quota", "8");
            json2.put("UserID", "42");

            StringEntity entity = new StringEntity(json2.toString()); 

            client.post(arg0.getContext(), PURL, entity, "application/json",
                    new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(String response) {
                    progressDialog.dismiss();
                    Toast.makeText(Activity3.this,response, Toast.LENGTH_LONG).show();
                }

            });

        }

WCF 服务

这就是我处理 POST 请求的方式

[OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "New")]
    bool SetAllEvents(Stream st);

此函数调用 JSON 解析器

public bool SetAllEvents(Stream s)
    {
        SetEvents se = new SetEvents();

        var data = se.SetNewEvent(s, connStr);
        return true;
    }

这就是我解析 JSON 的方式

StreamReader reader = new StreamReader(inputStream);
            string json = reader.ReadToEnd();

            var Jsonobject = JsonConvert.DeserializeObject<Events>(json);

            string eventName = Jsonobject.EventName;
4

1 回答 1

1

客户端的 httppost 标头是什么样的?以下内容可能对您有所帮助:

httpost.setEntity(se);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
于 2014-05-02T06:11:33.533 回答