开发者

C2DM authorization key CRLF and .Net WebRequest

We are using C2DM and are writing the server app in C#.

We obtain the authorization key with a POST using the WebRequest component. This works and we get back an encoded authorization key. The problem comes when we add this key to the auth header of the request that is going to send the message.

WebRequest request = WebRequest.Create("url");
...
request.Headers.Add(HttpRequestHeader.Authorization, "GoogleLogin auth=" + AuthorizationKey);

Since the key has the LF charact开发者_StackOverflow中文版er, we get an exception...

Unhandled Exception: System.ArgumentException: Specified value has invalid CRLF characters.
Parameter name: value

   at System.Net.WebHeaderCollection.CheckBadChars(String name, Boolean isHeaderValue)

   at System.Net.WebHeaderCollection.Add(String name, String value)

It would seem that CheckBadChars() is refusing the authorization key because it thinks there is a CRLF in the key, when in fact there is only a LF.

Does anyone have any ideas how we could get around this issue?


Maybe you’re just getting a linebreak at the end that you’re supposed to remove?

Edit: I read the documentation (at http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Response) and it says you’re supposed to get back a response that looks like this:

SID=DQAAAGgA...7Zg8CTN
LSID=DQAAAGsA...lk8BBbG
Auth=DQAAAGgA...dk3fA5N

There’s your three linebreaks. So what you need to do is pick out the the line starting with Auth= and grab the authorization token from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜