procedure TForm1.btn_getTokenClick(Sender: TObject); var sendData: string; url: string; ss: TStringStream; jsonData: isuperobject; begin url := 'https://aip.baidubce.com/oauth/2.0/token'; sendData := 'grant_type=client_credentials&client_id=' + Self.cxTextEdit_clientID.Text + '&client_secret=' + Self.cxTextEdit_clientSecret.Text; try ss := TStringStream.Create('', TEncoding.UTF8); ss.WriteString(sendData); self.NetHTTPClient1.Accept := 'text/html, application/xhtml+xml, */*'; self.NetHTTPClient1.ContentType := 'application/x-www-form-urlencoded'; //application/json self.NetHTTPClient1.AcceptEncoding := 'UTF-8'; ss.Position := 0; jsonData := SO(NetHTTPClient1.Post(url, ss).ContentAsString(tencoding.UTF8)); if Assigned(jsonData['access_token']) then begin cxMemo1.Clear; cxMemo1.Lines.Add(jsonData['access_token'].AsString); access_token := jsonData['access_token'].AsString; end; finally ss.Free; end; end;
client_id和client_secret 是你创建百度应用的时候生成的