ikod / dlang-requests

dlang http client library inspired by python-requests
Boost Software License 1.0
156 stars 32 forks source link

Send data to webpage #13

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hello,

i am using requests on windows and i am having problems to send data to a webpage. My current approach is this:

Request rq = Request();
Response rs = rq.exec!"GET"("http://somewebpage.org/", [parameter:data]);

Even though i get the response code '200' my website i am sending the data to does not react to the data (if it receives any, i don't know). If i just type this in my browser:

http://somewebpage.org/?parameter=data

everything works as intended.

What am i doing wrong?

ikod commented 8 years ago

Hello, which version of library do you use? Can you please enable debugging? To do so you can add line in front of call to exec: rq.verbosity=2; 20 Май 2016 г. 15:35 пользователь "GreatProjects" notifications@github.com написал:

Hello,

i am using requests on windows and i am having problems to send data to a webpage. My current approach is this:

Request rq = Request(); Response rs = rq.exec!"GET"("http://somewebpage.org/", [parameter:data]);

Even though i get the response code '200' my website i am sending the data to does not react to the data (if it receives any, i don't know). If i just type this in my browser:

http://somewebpage.org/?parameter=data

everything works as intended.

What am i doing wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/ikod/dlang-requests/issues/13

ghost commented 8 years ago

I use version 0.1.3 (so the latest i think?).

This is what i got on the terminal:

> GET /?temp=7 HTTP/1.1
> Connection: Close
> User-Agent: dlang-requests
> Accept-Encoding: gzip, deflate
> Host: nc
>
< HTTP/1.1 200 OK
< Date: Fri, 20 May 2016 20:16:38 GMT
< Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 mod_auth_passthrough/2.1 mod_wsgi/3.3 Python/2.7.1
< Last-Modified: Tue, 10 May 2016 19:36:02 GMT
< ETag: "28d4239-166c-532820a918700"
< Accept-Ranges: bytes
< Content-Length: 5740
< Connection: close
< Content-Type: text/html
< 5740 bytes of body received
>> Connect time: 186 ms, 31 ╬╝s, and 2 hnsecs
>> Request send time: 1 ms and 6 hnsecs
>> Response recv time: 362 ms, 51 ╬╝s, and 4 hnsecs
200
ikod commented 8 years ago

Query looks ok to me, I see no problem with query itself. Need more info from server side on request processing...

I use version 0.1.3 (so the latest i think?).

This is what i got on the terminal:

GET /?temp=7 HTTP/1.1 Connection: Close User-Agent: dlang-requests Accept-Encoding: gzip, deflate Host: nc

< HTTP/1.1 200 OK < Date: Fri, 20 May 2016 20:16:38 GMT < Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 mod_auth_passthrough/2.1 mod_wsgi/3.3 Python/2.7.1 < Last-Modified: Tue, 10 May 2016 19:36:02 GMT < ETag: "28d4239-166c-532820a918700" < Accept-Ranges: bytes < Content-Length: 5740 < Connection: close < Content-Type: text/html < 5740 bytes of body received

Connect time: 186 ms, 31 ╬╝s, and 2 hnsecs Request send time: 1 ms and 6 hnsecs Response recv time: 362 ms, 51 ╬╝s, and 4 hnsecs 200

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/ikod/dlang-requests/issues/13#issuecomment-220708306

ikod commented 8 years ago

BTW, server response have quite large body:

< Content-Length: 5740

It can contain some helpfull information if something go wrong. You can read responce body with code:

writeln(rs.responseBody);

ghost commented 8 years ago

Need more info from server side on request processing...

Basically i just check in my html if there is a parameter in the URL-line, if so i call a PHP-function on the server via AJAX with the parameter value.

ikod commented 8 years ago

Is there anything in the server logs, or in the server reply, that could help to understand what wrong with request?

Maybe you can repeat exactly the same request using other tool (like curl or wget) with debugging enabled to see if there is any difference?

ghost commented 8 years ago

In my PHP-file i have this routine:

        if($conn->query($sql) === TRUE){
            echo "Entered value successfully";
        } else {
            echo "error occurd: " . $conn->error;
        }

So i think there should be a message in the response if the function is ever called. But i only get the pure HTML/JavaScript from the site.

ghost commented 8 years ago

If i call my SQL.php function directly with:

Response rs = rq.exec!"GET"("http://site/SQL.php", ["action":"insertTemp","value":"7"]);

it works perfectly fine. But i don't understand why my html does not get that request before :(