Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用.net客户端使用java REST服务_C#_Java_Rest_Compact Framework - Fatal编程技术网

C# 使用.net客户端使用java REST服务

C# 使用.net客户端使用java REST服务,c#,java,rest,compact-framework,C#,Java,Rest,Compact Framework,我在使用java的.net和REST时遇到了一些问题。场景是:一台手持设备,带有.net compact framework 3.5,试图使用RESTeasy服务。这是我的(相关)客户代码: string url = textBox1.Text; url = "http://192.168.1.77:8080/demo-rest/myresource/message"; try { string json = "{id: 5, message: hello}"; HttpWebR

我在使用java的.net和REST时遇到了一些问题。场景是:一台手持设备,带有.net compact framework 3.5,试图使用RESTeasy服务。这是我的(相关)客户代码:

string url = textBox1.Text;
url = "http://192.168.1.77:8080/demo-rest/myresource/message";
try
{
    string json = "{id: 5, message: hello}";
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    req.ContentType = "application/json;charset=utf-8";
    req.KeepAlive = false;
    req.ProtocolVersion = HttpVersion.Version11;
    req.Method = "POST";
    byte[] postBytes = Encoding.UTF8.GetBytes(json);
    req.ContentLength = postBytes.Length;
    StreamWriter postwriter = new StreamWriter(req.GetRequestStream());
    postwriter.Write(postBytes);
    postwriter.Close();
    handleResponse((HttpWebResponse)req.GetResponse());
}
catch (Exception ex)
{
    textBox3.Text = url + "\n" + ex.Message;
}
非常简单,但是,我总是遇到相同的错误:HTTP 400错误请求。以下是(相关)堆栈跟踪:

Caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('S' (code 83)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

我的客户机出了什么问题?

您是否能够使用其他工具向您的REST服务发出成功请求?例如,直接从Firefox?您能告诉我们您的.net客户端到底向服务器发送了什么吗?顺便说一句,在这里使用
StreamWriter
并不是最好的选择,因为当您调用
postwriter.Close()时,它会关闭底层流。您可以简单地执行
req.GetRequestStream().Write
。我只需编写字符串,而不是UTF-8编码的字节数组。可能是编码问题?可能是编码问题。尝试从内容类型中删除charset=utf-8:
req.ContentType=“application/json;”您确实需要从HTTP请求中获取输出并打印它,以查看它的外观。。。