Saturday 15 March 2014

linux - no data recieved by recv() for https request in c++ -


I am a newbie in socket programming I am trying to create a socket on an HTTPS website. The socket has been successfully created and I want to send and send the header ... but I am not getting any header response as a response from RE (I) nor I'm receiving -1 ... program Only blocked there is the site open ports for https is 443 ...

  #include & lt; Iostream & gt; # Include & lt; Cstring & gt; Sys / socket.h & gt; #includes & lt; # Include & lt; Netdb.h & gt; using namespace std; Int main () {int position; Struct addrinfo hostInfo; Struct addrinfo * Host List; Memset (& hostInfo, 0, sized (hostInfo)); HostInfo.ai_family = AF_INET; HostInfo.ai_socktype = SOCK_STREAM; Cout & lt; & Lt; "Structures established ..." & lt; & Lt; Endl; Status = getaddrinfo ("academics.vit.ac.in", "https", & hostInfo, and host list); If (condition == 0) {cout & lt; & Lt; "Success" & lt; & Lt; Endl; // cout & lt; & Lt; HostList-> Ai_addr & lt; "" & Lt; & Lt; HostList-> Ai_socktype; } And {cout & lt; & Lt; "Feld!"; } Int socketd; Socketd = Socket (host list-> ai_family, hostList-> ai_socktype, hostList-> ai_protocol); If (socketd == -1) {cout & lt; & Lt; "Socket error \ n"; } And {cout & lt; & Lt; "Socket Success \ n"; } Cout & lt; & Lt; "Connecting \ n"; Condition = connect (socketd, hostList-> ai_addr, hostList-> ai_addrlen); If (condition == 0) {cout & lt; & Lt; "Success" & lt; & Lt; Endl; // cout & lt; & Lt; HostList-> Ai_addr & lt; "" & Lt; & Lt; HostList-> Ai_socktype; } And {cout & lt; & Lt; "Feld!"; } Cout & lt; & Lt; "\ NSending header \ n"; HTTP / 1.1 \ nHost: academics.vit.ac.in \ n Connection: Keep-alive \ nCache-Control: max-age = 0 \ n Accept: text / html, application / xhtml + xml, application / xml; Q = 0.9, * / *; Q = 0.8 \ n User-agent: Mozilla / 5.0 (X11; Linux X86_64) Apple WebKat / 537.36 (like KHtml, GECO) Chrome / 28.0.1500.52 Safari / 537.36 \ NReferrer: https: //academics.vit. Ac.in/\nAccept-Encoding: gzip, deflate, sdch \ nAccept-language: en-US, en; Q = 0.8 \ nCook: ASPSESSIONIDAWRSBBBS = HJBNNABBBIIADHKAGEFLELJK; ASPSESSIONIDCUTRADBT = GNMNDGBBFDJHBLHABHDGCCOO; ASPSESSIONIDCUQTABAT = IOAAMMNBACANEDJFMGMLMNJA; ASPSESSIONIDAUSQBCAS = GBNFBCOBEKIOJJHFPMJNMJII \ n \ n "; Court & lt;" \ n "& lt; & lt; Message & lt; endl; Int len ​​= strlen (msg); Ssize_t msgSize; MsgSize = send (socketd, msg, len, 0); if (msgSize == lane) {cout    

Thank you in advance :)

You Got Your Socket To block (using fnctl ()) and see if recv () check the error as well, this should give you more information.

See Man 2RV () @ .

No comments:

Post a Comment