Android HttpURLConnection POST未发送任何数据

Android HttpURLConnection POST未发送任何数据,android,asp.net,json,post,httpurlconnection,Android,Asp.net,Json,Post,Httpurlconnection,我正在本地主机上运行ASP.net JSON服务。我正在从Android应用程序向服务器发送JSON POST请求。服务器正在接收连接,但没有POST数据(我通过设置一个断点来确认这一点,该断点在我从Android应用程序发布后命中)。我得到的HttpURLConnection响应代码是200 OK。但是,服务器没有接收到数据。我不确定是否正在发送任何数据。我的android代码是(包装在AsyncTask中): C#/ASP.NET服务合同。父实例为空,但应包含通过POST发送的数据: [Se

我正在本地主机上运行ASP.net JSON服务。我正在从Android应用程序向服务器发送JSON POST请求。服务器正在接收连接,但没有POST数据(我通过设置一个断点来确认这一点,该断点在我从Android应用程序发布后命中)。我得到的HttpURLConnection响应代码是200 OK。但是,服务器没有接收到数据。我不确定是否正在发送任何数据。我的android代码是(包装在AsyncTask中):

C#/ASP.NET服务合同。父实例为空,但应包含通过POST发送的数据:

[ServiceContract]
    public interface IRestServiceParent
    {

        [WebInvoke(UriTemplate = "{dummy}", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        Parent PostParent(string dummy, Parent instance);
    }

public Parent PostParent(string dummy, Parent instance)
        {
            var result = MasterStorageStore.Instance.PostParent(instance);
            if (result == null) return emptyParent;

            return NewCopy(result);
        }

也许你应该尝试添加一个
out.flush()
after
out.write(postBody.getBytes(“UTF-8”)

我通过一个简单的PHP脚本发现,出于某种原因,尽管设置了
setRequestMode(“POST”)
setDoOuput(true)
HttpURLConnection
被作为
GET
发送,而不是
POST
。我不知道为什么。

这导致400个错误请求。不过,谢谢。哦,我刚刚发现您没有将urlConnection的请求模式设置为“POST”。尝试
urlConnection.setRequestMode(“POST”)
连接()之前
。对此不确定,但也许它会起作用。setDoOutput(true)就是这样做的。我确实尝试过setRequestMode(“POST”),但没有成功。
[ServiceContract]
    public interface IRestServiceParent
    {

        [WebInvoke(UriTemplate = "{dummy}", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        Parent PostParent(string dummy, Parent instance);
    }

public Parent PostParent(string dummy, Parent instance)
        {
            var result = MasterStorageStore.Instance.PostParent(instance);
            if (result == null) return emptyParent;

            return NewCopy(result);
        }