The remote server returned an error: (403) Forbidden. during post request…?

南笙酒味 提交于 2019-12-24 14:06:31

问题


I try to make small application for myself and I found this application How to upload video on Dailymotion with c# ?? Is somebody has a complete code?

When I tried every thing but publishing is not working. I used fiddler but I cant find the error. Here is the code

 var request = WebRequest.Create("https://api.dailymotion.com/me/videos?url=" + Uri.EscapeUriString(uploadResponse.url));
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Headers.Add("Authorization", "OAuth " + accessToken);

        var requestBytes = Encoding.UTF8.GetBytes("title=test 123&channel=Funny&tags=Humor&description=Testing testing&published=true");

        var requestBytes = Encoding.UTF8.GetBytes(requestString);

        var requestStream = request.GetRequestStream();

        requestStream.Write(requestBytes, 0, requestBytes.Length);

        var response = request.GetResponse();

        var responseStream = response.GetResponseStream();
        string responseString;
        using (var reader = new StreamReader(responseStream))
        {
            responseString = reader.ReadToEnd();
        }

When it reaches request.GetResponse() it gives the error. So what is the problem here..?


回答1:


I believe you need to get rid of the "me" in the url as you're using OAuth instead of basic authentication, like this:

"https://api.dailymotion.com/videos?url="

Instead of:

"https://api.dailymotion.com/me/videos?url="

At least in a quick scan that looks like it's it, I wrote an auto-publisher for a client a year ago and it didn't use the me in the url. My credentials are invalid now, so can't test it unfortunately. It seems to be a bug in the answer you linked.

If you can read other languages, I found it helpful just going through their SDKs and converting the code:

http://www.dailymotion.com/doc/api/sdk-php.html

https://github.com/dailymotion/dailymotion-sdk-php/blob/master/Dailymotion.php



来源:https://stackoverflow.com/questions/11565057/the-remote-server-returned-an-error-403-forbidden-during-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!