Jump to content
Sign in to follow this  
-FN

[Problema] Erro 403 C# HTTPRequest

Recommended Posts

-FN

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/";
            try
            {
                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();
                objHttpWebResponse.Close();

                objHttpWebRequest = null;

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

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

Share this post


Link to post
Share on other sites
Super Oliks

vi alguma coisa sobre isso..... tente tirar a linha

objHttpWebRequest.ContentType = "application/x-www-form-urlencoded";

, e definir a propriedade Accept para "text / html" 

request.Accept = "text/html"

Não sei se ajuda.....

Share this post


Link to post
Share on other sites
-FN

Já consegui resolver. Dava esse erro porque não tinha o Content.Lenght

No entanto, surgiu-me outro imprevisto. Não tem o encode correcto. Como posso por para UTF8, o return ?

Share this post


Link to post
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
Sign in to follow this  

×
×
  • 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.