向Yahoo!添加联系人时400 Bad Request信使

时间:2016-04-18 03:37:10

标签: vb.net yahoo yahoo-api

我想使用Api和VB NET将联系人添加到yahoo messenger。

这是我的代码:

Dim url As String = "http://developer.messenger.yahooapis.com/v1/group/{{GROUP}}/contact/yahoo/{{USER}}"
    url &= "?oauth_consumer_key=" & sConsumer_key
    url &= "&oauth_nonce=" & GetRandom(10000, 50000)
    url &= "&oauth_signature=" & sConsumer_secret & "%26" & oauth_token_secret_value
    url &= "&oauth_signature_method=PLAINTEXT"
    url &= "&oauth_timestamp=" & TimeOfDay
    url &= "&oauth_token=" & oauth_token_value
    url &= "&oauth_version=1.0"
    url &= "&sid=" & YmsgSessionID

    url = Replace(url, "{{GROUP}}", group)
    url = Replace(url, "{{USER}}", user)

    '//additional header
    Dim request As WebRequest = Nothing
    Dim webAddress As Uri
    webAddress = New Uri(url)

    ' Create the web request  
    request = DirectCast(WebRequest.Create(webAddress), HttpWebRequest)
    Dim myheaders As WebHeaderCollection

    ' set type to GET
    request.Method = "PUT"
    request.ContentType = "application/json"
    myheaders = request.Headers
    myheaders.Add("charset", "utf-8")

    '----- get response
    Dim response As WebResponse = request.GetResponse()

    Dim dataStream As Stream = response.GetResponseStream()
    Dim reader As New StreamReader(dataStream)
    Dim responseFromServer As String = reader.ReadToEnd()

当我执行它时,我收到了一个异常400错误请求:

Dim response As WebResponse = request.GetResponse()

我尝试使用相同的url和DELETE方法(request.Method="DELETE")并且它可以工作,但是当我更改为PUT方法时,我得到400个错误请求。有想法的人吗?

0 个答案:

没有答案