1

我正在尝试在过去一周在 LinkedIn 中添加帖子评论

我已经写了这段代码

    protected void Page_Load(object sender, EventArgs e)
    {
        string xmlContent = "<?xml version='1.0' encoding='UTF-8'?>";
        xmlContent += "<comment><text>Check out</text></comment>";
        byte[] databytes = Encoding.Default.GetBytes(xmlContent);

        var credentials = new Hammock.Authentication.OAuth.OAuthCredentials
        {
            Type = OAuthType.AccessToken,
            SignatureMethod = OAuthSignatureMethod.HmacSha1,
            ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
            ConsumerKey = "*********",
            ConsumerSecret = "*********",
            Token = "*********",
            TokenSecret = "*********",
            Version = "1.0"
        };

        var client = new Hammock.RestClient() { Authority = "http://api.linkedin.com/v1/posts" };
        var request = new Hammock.RestRequest() { Path = "/56787878/comments", Method = Hammock.Web.WebMethod.Post, Timeout = new TimeSpan(0, 0, 5), Credentials = credentials };
        request.AddHeader("Content-Type", "application/xml");
        client.AddParameter("","");
        client.AddPostContent(Encoding.UTF8.GetBytes(xmlContent));
        //request.AddPostContent(Encoding.UTF8.GetBytes(xmlContent));
        var response = client.Request(request);
        Response.Write(response.Content);
     }

我收到以下 Xml 格式的错误

 <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
 <error>  
 <status>400</status>
 <timestamp>1374494502579</timestamp>
 <request-id>QM4MYPEKJJ</request-id>  
 <error-code>0</error-code>
 <message>Couldn't parse message document: error: Unexpected end of file after null</message>\n</error>

有人处理这个错误吗?提前致谢。

4

0 回答 0