开发者

WebRequest C# 403 Error

开发者 https://www.devze.com 2022-12-09 09:49 出处:网络
Okay so here\'s what I\'m doing. I\'m making a request to a server to pull down a file. I do this by making a WebRequest to the website the getting the response just as you usually would, although i g

Okay so here's what I'm doing. I'm making a request to a server to pull down a file. I do this by making a WebRequest to the website the getting the response just as you usually would, although i get a 403 error saying i don't have permissions.

Problem is when i plug the URL into Google Chrome I get redirected and the file i requested comes down. I've tried the URL on other browsers and开发者_JAVA百科 get the 403 error.

What is Google Chrome doing that allows it to bypass the 403 error? I've tried using the Google Chrome User Agent, but that doesn't help me.

Help


Possibly the web server recognizes the Chrome user agent and allows the file to be downloaded by it, but not by other user agents. Set up your WebRequest to use the same user agent strings and settings as Google Chrome - by default it might be using the IE settings.

Edit: Here's instruction from MSDN about how to set the WebRequest user agent string. To find out the user agent of any browser, enter this into its address bar:

javascript:prompt('my user agent string is', navigator.userAgent);


The 403 status code indicates the resource you're attempting to reach is Forbidden. As in, don't ask because you're not getting it. This differs from the 401 code in that an Authorization challenge is presented before the server will confirm delivery of the resource.

While this could be programmatic configuration, this might also be explained by access restrictions on the resource as configured through the web server.

Can you verify that the downloaded resource in Google Chrome is the expected resource you're attempting to reach?


Thanks for the help. None of your answers helped me directly, but thanks for trying.

My Program was trying to pull a file off a server. I had figured out how to get around the authentication issues and finding the file on the server while using Chrome. It turns out that their web service is more advanced using user sessions.

Basically I didn't have access to the webservice commands, so all i could do is use the basic http urls to get a predefined response. The files url that i used to get the file of the server was not unique, it was dynamic depending on the webbrowser / the session. I was using the HTTPRequest object to get the HTML file so i could parse it. With the html file i parsed it to find out the dynamic ID of the file (I thought it was unique). Then I'd attach that to the end of a URL. In Chrome I would be redirected and presented with the download prompt. Problem was that I needed the webbrowser object when i wanted to pull down the file. Knowing this i used the webbrowser object to get the file ID, then used the same webbrowser object (Technically same sessions according the webserver) to pull down the file.

It's rather complicated. Basically my program is a little hack that provides functionality that the server is try block.

Hope this assisted you guys in any of your future projects.

0

精彩评论

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