Spinneret to remote server with credentials
daill1
Posts: 8
Hey, I am trying to connect to a remote server via the spinneret by sending an HTTP Header POST request. The directory on the server I am trying to talk to is password protected, which I enabled through cPanel. I am wondering if anyone knows the correct syntax for sending the request in SPIN or if I need to know more information on the server side. My code so far:
PUB PostData(id) | st, size, idx, tempMask pst.str(string(13,"Post Data!",13)) tempMask := tcpMask tcpMask := SetTcpSocketMaskById(id, 0) Socket.Close(id) pause(delay) InitializeSocket2(id) pause(delay) 'Get My IP pst.str(string(13, "Getting Assigned IP ",13)) Socket.Connect(id) pause(delay) repeat while !Socket.Connected(id) pst.str(string(13, "Sending Header ",13)) StringSend(id, string("POST /spinneret/formtest.php HTTP/1.1", 13, 10)) StringSend(id, string("Keep-Alive: 115", 13, 10)) StringSend(id, string("Host: rcc.cfbtechnologies.com", 13, 10)) StringSend(id, string("Connection: keep-alive", 13, 10)) StringSend(id, string("Content-Type: application/x-www-form-urlencoded", 13, 10)) StringSend(id, string("Content-length: 45", 13, 10, 13, 10)) StringSend(id, string("Authorization: Basic cmNjOkFXVTc0XmJWVEJ2fg== ", 13, 10)) ' rcc:AWU74^bVTBv~ user:pass pst.str(string(13, "Waiting for response",13,13)) 'Clear the buffer bytefill(@tempBuff, 0, TEMP_BUFFER) repeat until size := Socket.rxTCP(id, @rxdata) ' Find and save message body ' Write the message to the terminal idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true) bytemove(@tempBuff, @rxdata+idx+4, strsize(@rxdata+idx+4)) pst.str(@tempBuff) pst.str(string(13, "Disconnect and reset socket: ")) pst.dec(id) pst.char(13) {repeat until size := Socket.rxTCP(id, @rxdata) pst.str(@rxdata) AppendLog(@rxdata) 'Find and print the message body 'idx := str.MatchPattern(@rxdata, string(13,10,13,10), 0, true) 'pst.str(@rxdata+idx+4) } 'Reset the socket Socket.Disconnect(id) InitializeSocket(id) 'Reset the tcpMask tcpMask := tempMaskThe response is a '401 Authorization Required' and I am assuming that the server wants it base64 encoded. I am beginning to wonder if this is even possible or if I need to get with support from my server provider. What I have found in my research is that I should be able to Post the username and password to the server in this way and that this is the acceptable way to access the cPanel password protected directory. Anyone have any ideas?
Comments
Are you sure the username and password are correct? I just tried from a browser and received an error using the credentials provider in your post.
HTTP GET
HTTP POST
The Content-Length: header is required when submitting a POST. Otherwise your server will throw a 403 Forbidden followed by a 404 Not Found. The 404 is thrown because the designated error document does not exist. You should fix the later error...