Im doing something wrong?

Back to Problem Solutions forum

Leonid_Manieiev     2015-06-26 20:06:39

Hi

Im trying to solve problem 176 "Say 100"

Here is my code:

#include <stdio.h>
#include <curl/curl.h>

int main()
{
    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();

    if(curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, "http://codeabbey.sourceforge.net/say-100.php");
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "X21+/FziHBxzqmEjYA/eWjU3");
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }

    return 0;
}

I cant understand what Im doing wrong, but on each run of programm, i get response: "error: No token found"

P.S. Im not asking for solution, but for advice.

Leonid_Manieiev     2015-06-26 20:08:37

Sorry, if my question is a bit stupid. Its my first time, then Im working with request.

Guy Gervais     2015-06-26 22:37:38
User avatar

Your question is fine, don't worry.

I think the format you need to use is: "token: X21+/FziHBxzqmEjYA/eWjU3"; you need to include the "token : " part.

Leonid_Manieiev     2015-06-26 23:14:39

I tried, but didnt help. Same message: "error: No token found"

Guy Gervais     2015-06-27 11:52:45
User avatar

If you're on Windows, you could try to use a tool like Fiddler2 to see what is going on during the communication. Similar "http-sniffing" tools exist for Linux or any other platform. That should help you see what is going on when your program runs.

Leonid_Manieiev     2015-06-27 15:30:44

Is there an easier way? Because I downloaded Fiddler2 and you know, there are a lot of unnecessary things and I think it will take a while me to understand where should I click to get useful information and fix the problem.

Guy Gervais     2015-06-27 20:57:56
User avatar

Unnecessary things? Fiddler should let you see the messages being exchanged between your PC and the server. Just click on the "raw" tab to see exactly what's being sent and received.

If that's too complicated, you can try some other library or a different language. C++ is not the web-friendliest language to do those problems in.

Leonid_Manieiev     2015-06-27 21:39:01

So, I should run Fiddler, open "raw" tab and then run my programm, and I will see what is being sent and received, right?

Leonid_Manieiev     2015-06-27 21:50:25

Well, I found raw tab, but then I run my program, there is no new session(my session) added in Fiddler, so I cant see any info of it. What should I do?

Quandray     2015-06-29 14:33:13
User avatar

I used cURL

Try using the format "token=X21+/FziHBxzqmEjYA/eWjU3" with CURLOPT_POSTFIELDS

I also had the line curl _ easy _ setopt(curl,CURLOPT_POST,1);

Leonid_Manieiev     2015-07-02 12:34:46

Thanks, this form of token "token=X21+/FziHBxzqmEjYA/eWjU3" works.

Leonid_Manieiev     2015-07-02 13:50:21

Well, another problem. I get secret number from server. My next request should be in form?:

curl_easy_setopt(curl1, CURLOPT_POSTFIELDS, "token=nXdWhRyYNbdpG8Vf1+KN9DQx");
curl_easy_setopt(curl1, CURLOPT_POSTFIELDS, 100-secret_number);

or:

curl_easy_setopt(curl1, CURLOPT_POSTFIELDS, "token=nXdWhRyYNbdpG8Vf1+KN9DQx");
curl_easy_setopt(curl1, CURLOPT_POSTFIELDS, "answer=" 100-secret_number);

or how should it looks like?

Quandray     2015-07-02 14:35:59
User avatar

If your secret is 74, "token=nXdWhRyYNbdpG8Vf1+KN9DQx&answer=26"

Leonid_Manieiev     2015-07-02 15:36:47

I`ll try, thank you.

Please login and solve 5 problems to be able to post at forum