Announcement

Collapse
No announcement yet.

TcpLinkClient port 443 instead of 80, not working?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    TcpLinkClient port 443 instead of 80, not working?

    Hi,

    Could you please tell me why the code below does not work (the requested web content does not return) if the port is changed to 443 - for https connection? (please see the last line: TargetPort=80).
    (code downloaded from here https://api.unrealengine.com/udk/Thr...html#Downloads).

    (the web content does not return).

    Thanks.

    Code:
    /*
     * An example usage of the TcpLink class
     *  
     * By Michiel 'elmuerte' Hendriks for Epic Games, Inc.
     *  
     * You are free to use this example as you see fit, as long as you
     * properly attribute the origin.
     */
    class TcpLinkClient extends TcpLink;
    
    var string TargetHost;
    var int TargetPort;
    
    event PostBeginPlay()
    {
        super.PostBeginPlay();
        // Start by resolving the hostname to an IP so we can connect to it
        // Note: the TcpLink modes have been set in the defaultproperties
        `Log("[TcpLinkClient] Resolving: "$TargetHost);
        resolve(TargetHost);
    }
    
    event Resolved( IpAddr Addr )
    {
        // The hostname was resolved succefully
        `Log("[TcpLinkClient] "$TargetHost$" resolved to "$ IpAddrToString(Addr));
    
        // Make sure the correct remote port is set, resolving doesn't set
        // the port value of the IpAddr structure
        Addr.Port = TargetPort;
    
        `Log("[TcpLinkClient] Bound to port: "$ BindPort() );
        if (!Open(Addr))
        {
            `Log("[TcpLinkClient] Open failed");
        }
    }
    
    event ResolveFailed()
    {
        `Log("[TcpLinkClient] Unable to resolve "$TargetHost);
        // You could retry resolving here if you have an alternative
        // remote host.
    }
    
    event Opened()
    {
        // A connection was established
        `Log("[TcpLinkClient] event opened");
        `Log("[TcpLinkClient] Sending simple HTTP query");
    
        // The HTTP request
        SendText("GET / HTTP/1.0"$chr(13)$chr(10));
        SendText("Host: "$TargetHost$chr(13)$chr(10));
        SendText("Connection: Close"$chr(13)$chr(10));
        SendText(chr(13)$chr(10));
    
        `Log("[TcpLinkClient] end HTTP query");
    }
    
    event Closed()
    {
        // In this case the remote client should have automatically closed
        // the connection, because we requested it in the HTTP request.
        `Log("[TcpLinkClient] event closed");
    
        // After the connection was closed we could establish a new
        // connection using the same TcpLink instance.
    }
    
    event ReceivedText( string Text )
    {
        // receiving some text, note that the text includes line breaks
        `Log("[TcpLinkClient] ReceivedText:: "$Text);
    }
    
    defaultproperties
    {
        TargetHost="www.google.com"
        TargetPort=80    //does not work if changed to 443??? (www.google.com:443 works normally).
    }
    Last edited by 9454; 04-23-2018, 06:44 AM.

    #2
    "does not work" means the requested web content (www.google.com) does not return.

    http://i1289.photobucket.com/albums/...pszhyrsav3.png

    Click image for larger version

Name:	2018-04-23_17h49_23.png
Views:	68
Size:	105.9 KB
ID:	1465304
    Last edited by 9454; 04-23-2018, 07:04 AM.

    Comment


      #3
      That is because google.com does not return anything if the http request is wrong.
      If I try to connect to another site: amazon.com, the server returns useful information:


      PHP Code:
      [0139.68ScriptLog: [TcpLinkClientResolvingamazon.com
      [0139.72ScriptLog: [TcpLinkClientamazon.com resolved to 176.32.98.166:443
      [0139.72ScriptLog: [TcpLinkClientBound to port59086
      [0139.73LogCheckConnectionAttemptConnection attempt has not yet completed.
      [
      0139.97LogCheckConnectionAttemptConnection attempt has not yet completed.
      [
      0139.98ScriptLog: [TcpLinkClientevent opened
      [0139.98ScriptLog: [TcpLinkClientSending simple HTTP query 176.32.98.166:443
      [0139.98ScriptLog: [TcpLinkClientend HTTP query
      [0140.47ScriptLog: [TcpLinkClientReceivedText:: HTTP/1.1 400 Bad Request
      Server
      Server
      Date
      Tue24 Apr 2018 01:03:43 GMT
      Content
      -Typetext/html
      Content
      -Length265
      Connection
      close

      <html>
      <
      head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
      <
      body bgcolor="white">
      <
      center><h1>400 Bad Request</h1></center>
      <
      center>The plain HTTP request was sent to HTTPS port</center>
      <
      hr><center>Server</center>
      </
      body>
      </
      html>

      [
      0140.47ScriptLog: [TcpLinkClientevent closed 

      It says "400 The plain HTTP request was sent to HTTPS port".
      So I need to figure out how to send the correct https requests...

      Comment


        #4
        I used this tutorial as a guide and didn't have any trouble http://www.alexander-fisher.com/?p=159

        Comment


          #5
          Thanks for the link. In that tutorial, he uses port 80 (http).
          My issue is with port 443 (https).

          Comment


            #6
            Seems I didn't understand the question at all actually.
            This seems like a question for web developer forums (how a HTTPS request should look like written down) since on the Unrealscript side you just provide a text string.

            Comment

            Working...
            X