Jump to content

[Problema] Erro 403 C# HTTPRequest


Recommended Posts

Quando faço um HTTPRequest para um certo domínio, ele retorna o erro 403.

Há forma de corrigir isto ?

Já experimentei por GET e funciona. Por POST não.

No entanto, deixo aqui o código do meu httprequest:

string phpRequest(string strURL, string strRequest)
            // --- WebSite URL
            string url = "http://www.***.com/teste/";
                strURL = url + strURL + strRequest;
                HttpWebResponse objHttpWebResponse = null;
                string strResponse = "";

                HttpWebRequest objHttpWebRequest;
                objHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
                objHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
                objHttpWebRequest.PreAuthenticate = true;
                objHttpWebRequest.Method = "POST";

                objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();

                //recebe as respostas em utf7
                StreamReader objStreamReader = new StreamReader(objHttpWebResponse.GetResponseStream(), new UTF7Encoding());
                strResponse = objStreamReader.ReadToEnd();

                objHttpWebRequest = null;

                return strResponse;
            catch (Exception error)
                // --- Retornar erro
                return error.Message;

            return "";
        // --- Fim HTTP Request

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.