[.NET] Http Request -> WebException 403

Dieses Thema im Forum "Programmierung & Entwicklung" wurde erstellt von furious1, 31. August 2010 .

Schlagworte:
Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 31. August 2010
    Http Request -> WebException 403

    Hi,

    würde gerne im Hintergrund etwas an ein PHP Script übergeben.

    Ich hab nun 2 Sachen ausprobiert -> Gleicher Fehler.

    1.
    Code:
    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Text
    
    Dim request As WebRequest = WebRequest.Create("http://sub.domain.net/index.php?r=1&d=" & txtMessage.Text & "&t=fz")
    Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
    2.
    Code:
    Dim myWebClient As System.Net.WebClient
    myWebClient = New System.Net.WebClient()
    myWebClient.DownloadString("http://sub.domain.net/index.php?r=1&d=" & txtMessage.Text & "&t=fz")
    Error: (403 Unzulässig.)
    Spoiler
    Code:
    System.Net.WebException wurde nicht behandelt.
     Message=Der Remoteserver hat einen Fehler zurückgegeben: (403) Unzulässig.
     Source=System
     StackTrace:
     bei System.Net.HttpWebRequest.GetResponse()
     bei X.Form2.PictureBox1_Click(Object sender, EventArgs e) in C:\...\Form2.vb:Zeile 84.
     bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
     bei System.Windows.Forms.Control.WndProc(Message& m)
     bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
     bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
     bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
     bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
     bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
     bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
     bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
     bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
     bei X.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 82.
     bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
     bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
     bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     bei System.Threading.ThreadHelper.ThreadStart()
     InnerException: 
    

    Wenn ich anstatt der URL einfach lokal XAMPP nehme (http://localhost/...) funktioniert das Ganze einwandfrei. Damit hab ich mich über 4h befasst, klappt leider nicht.

    Würde mich über hilfreiche Antworten freuen.

    Gruß
     
  2. 31. August 2010
    AW: Http Request -> WebException 403

    Das hat wahrscheinlich (ziemlich sicher) mit dem Server zu tun. Anhand des Codes wird man (sehr wahrscheinlich) keinen Fehler feststellen können.

    HTTP RFC sagt etwa das:

     
  3. 31. August 2010
    AW: Http Request -> WebException 403

    Hm alles klar, hat jmd. evt. eine Lösung, wie ich das sonst anstellen kann?

    Wie gesagt, es soll nur eine URL aufgerufen werden damit was übergeben wird an ein PHP Script.
     
  4. 31. August 2010
    AW: Http Request -> WebException 403

    Wie gesagt, der Server scheint dich aktiv abzuwehren. Da kannst du nicht viel machen.

    Du könntest das ganze nochmal per SSL versuchen, ich bin mir jedoch nicht sicher ob das was verändert. Des weiteren kann ich dazu leider keine Hilfestellung geben, da ich mich damit noch net befasst habe.
     
  5. 31. August 2010
    AW: Http Request -> WebException 403

    setz einen eigenen user-agent sowie accpet-encoding (usw), dann sollte der server dich nicht mehr blocken.

    [VB.Net] WebRequest mit Cookie @ .NET Web und Kommunikation - tutorials.de: Tutorial, Forum, Anleitung & Hilfe
     
  6. 31. August 2010
    Zuletzt von einem Moderator bearbeitet: 15. April 2017
    AW: Http Request -> WebException 403

    Dann kannste diese Funktion hier nehmen (hab ich vor ner Weile gebastelt):

    Code:
     Private Function httpPost(ByVal URL As String) As String
     Try
     Dim webRequest As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(URL), System.Net.HttpWebRequest)
     Dim cookies As New Net.CookieContainer
     webRequest.CookieContainer = cookies 'Cookies
     webRequest.UserAgent = "Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.7.3) Gecko/20040924 Epiphany/1.4.4 (Ubuntu)" 'UserAgent
     Dim webResponse As System.Net.HttpWebResponse = CType(webRequest.GetResponse(), System.Net.HttpWebResponse)
     Dim responseStream As System.IO.Stream = webResponse.GetResponseStream()
     Dim responseEncoding As System.Text.Encoding = System.Text.Encoding.UTF8
     Dim responseReader As New IO.StreamReader(responseStream, responseEncoding)
     Dim responseContent As String = responseReader.ReadToEnd()
     Return responseContent
     Catch ex As Exception
     Return "Error while sending post data:" & ex.Message
     End Try
     End Function
    Den Cookie Container musst du ggf. außerhalb der Funktion platzieren, um die Cookies beim nächsten Aufruf weiter verwenden zu können.

    //
    [Visual Basic] [08][.net] Hilfe zu HttpWebRequest benötigt (POST)
    Hier hatte ich sie schon mal gepostet
     
  7. 31. August 2010
    AW: Http Request -> WebException 403

    Vielen vielen Dank!

    Mit deiner Funktion läufts

    Gruß
     
  8. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.