我必須在Delphi上編寫客戶端,它應該將產品,客戶等添加到WP WooCommerce。如果我做GET請求,我會從我的WP中獲取一些數據。我必須發送該json。
這裏是我的GET請求返回json string如何將產品,客戶等郵寄到WordPress WooCommerce插件通過Delphi
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.JSON, IPPeerClient, System.Rtti,
System.Bindings.Outputs, Vcl.Bind.Editors, Data.Bind.EngExt,
Vcl.Bind.DBEngExt, Vcl.StdCtrls, Data.Bind.Components, REST.Client,
Data.Bind.ObjectScope, REST.Authenticator.OAuth, REST.Authenticator.Basic,
REST.Authenticator.Simple, REST.Types, REST.JSON, IdHMACSHA1, EncdDecd, HTTPApp,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTResponse1: TRESTResponse;
HTTPBasicAuthenticator1: THTTPBasicAuthenticator;
Button2: TButton;
Button3: TButton;
Memo2: TMemo;
Edit1: TEdit;
IdHTTP1: TIdHTTP;
Memo3: TMemo;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
jValue: TJSONValue;
begin
HTTPBasicAuthenticator1.Username :=
'ck_6f28f594097d674abf96ebb6b6856ab18b9*****';
HTTPBasicAuthenticator1.Password :=
'cs_1eede52f328af091dca5d6c7e0b6a0abc55*****';
RESTClient1.Params.Clear;
RESTClient1.AddParameter('consumer_key', HTTPBasicAuthenticator1.Username, TRESTRequestParameterKind.pkGETorPOST);
RESTClient1.AddParameter('consumer_secret', HTTPBasicAuthenticator1.Password, TRESTRequestParameterKind.pkGETorPOST);
RESTRequest1.Resource := 'products';
RESTRequest1.Execute;
jValue := RESTResponse1.JSONValue;
Memo1.Lines.Add(jValue.ToString);
end;
有人能解釋或說明如何和在數據類型,我應該把我的POST請求例如覺得我的產品名稱,編號和價格? here is documentation of WooCommerce if it helps 謝謝))
所以,我解決我的問題))
我嘗試發送{"customers":[{"email":"[email protected]
在我的GET請求或{"email":"[email protected]
在WooCommerce的文檔。我試圖發送它沒有陣列太{"customers":{"email":"[email protected]
。
所有的時間我得到了我的錯誤{"code":"json_missing_callback_param","message":"Missing parameter data"}
但所有你需要的只是從文件發送「客戶」而不是「客戶」爲目標,所有參數(電子郵件,FIRST_NAME ....)
因此,這裏是我的代碼工作,我現在可以發佈:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.JSON, IPPeerClient, System.Rtti,
System.Bindings.Outputs, Vcl.Bind.Editors, Data.Bind.EngExt,
Vcl.Bind.DBEngExt, Vcl.StdCtrls, Data.Bind.Components, REST.Client,
Data.Bind.ObjectScope, REST.Authenticator.OAuth, REST.Authenticator.Basic,
REST.Authenticator.Simple, REST.Types, REST.JSON, IdHMACSHA1, EncdDecd, HTTPApp,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
RESTResponse1: TRESTResponse;
HTTPBasicAuthenticator1: THTTPBasicAuthenticator;
Button2: TButton;
Button3: TButton;
Memo2: TMemo;
Edit1: TEdit;
IdHTTP1: TIdHTTP;
Memo3: TMemo;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
jValue: TJSONValue;
begin
HTTPBasicAuthenticator1.Username :=
'ck_6f28f594097d674abf96ebb6b6856ab18b9*****';
HTTPBasicAuthenticator1.Password :=
'cs_1eede52f328af091dca5d6c7e0b6a0abc55*****';
RESTClient1.Params.Clear;
RESTRequest1.Resource := 'customers';
RESTRequest1.ResourceSuffix :=
'?consumer_key={consumer_key}&consumer_secret={consumer_secret}';
RESTRequest1.AddParameter('consumer_key', HTTPBasicAuthenticator1.Username,
TRESTRequestParameterKind.pkURLSEGMENT);
RESTRequest1.AddParameter('consumer_secret', HTTPBasicAuthenticator1.Password,
TRESTRequestParameterKind.pkURLSEGMENT);
RESTRequest1.AddBody(a.ToJSON, ctAPPLICATION_JSON);
RESTRequest1.Execute;
jValue := RESTResponse1.JSONValue;
Memo1.Lines.Add(jValue.ToString);
end;
提供解釋陪你的答案要分清楚。 – BlackPearl