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

时间:2014-05-12 16:35:13

标签: c# java rest compact-framework

我正在通过java面对.net和REST的一些问题。场景是:一个带有.net紧凑框架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 Bad Request。这是(相关的)堆栈跟踪:

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

我的客户有什么问题?

0 个答案:

没有答案