Jump to content

Did someone work to CURL in Delphi?


elGringo

Recommended Posts

Faced with uploading to keep2share through their API. They request through CURL

 

Api here

https://github.com/keep2share/api

 

I tried to use Indy but it works partly

 

From API

"All request parameters must be encoded to JSON and sent using the POST method All methods return operation status (success, fail) and additional data in JSON"

Ok they say we need to get auth_token for all other operations. I do it like this

function TForm1.GetAuthtoken:string;

    var

      JSONObject:TJSONObject;
      ServerAnswer: string;
      JsonString: string;
      ss:TStringStream;
      i: Integer;


    begin



    JSONObject:=TJSONObject.Create;

    JSONObject.AddPair( (TJSONPair.Create('username','panteleevstas@gmail.com' )) );
    JSONObject.AddPair( (TJSONPair.Create('password','SLwA63' )) );

    JsonString:=JSONObject.ToString;


    ss:=TStringStream.Create(JsonString);


    ServerAnswer:=idHTTP.Post('http://keep2share.cc/api/v2/login', ss);

    Memo.Lines.Add(ServerAnswer);

    JSONObjectAfter:=TJSONObject.ParseJSONValue(ServerAnswer) as TJSONObject;

    Result:=JSONObjectAfter.Pairs[2].JsonValue.ToString;;
    Result.Substring(1,Result.Length-1);
    Memo.Lines.Add(Result);

    FreeAndNil(JSONObject);

    end;

I succsesfully get auth_token

 

Then i try to test some function and get ERROR 403 in sppite of i use the same method as above which works

 procedure TForm1.bTestClick(Sender: TObject);

    var JSONObject:TJSONObject;
        ServerAnswer: string;
        JsonString: string;
        ss:TStringStream;


    begin

    //


    JSONObject:=TJSONObject.Create;

    JSONObject.AddPair( (TJSONPair.Create('auth_token',GetAuthtoken )) );

    JsonString:=JSONObject.ToString;


    ss:=TStringStream.Create(JsonString);


    ServerAnswer:=idHTTP.Post('http://keep2share.cc/api/v2/test', ss);

    Memo.Lines.Add(ServerAnswer);


    FreeAndNil(JSONObject);


    end;

Maybe for CURL some special lib? Did anyone faced?

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...