Httpful後我有一點laravel應用程序,我添加了http://phphttpclient.com/ - httpful REST客戶端與外部API的工作 - http://en.help.mailstore.com/spe/Management_API_-_Using_the_API用urlencode
我能「說話」與郵件存儲API。這裏有一個例子:
public function GetEnvironmentInfo()
{
$uri = 'https://bla.com:8474/api/invoke/GetEnvironmentInfo';
$response = Httpful::post($uri)
->authenticateWith('admin', 'password')
->send();
$errors = $response->body->error;
$version = $response->body->result->version;
$license = $response->body->result->licenseeName;
dd($version . $license . $errors);
}
該函數的工作原理。但是當我嘗試向api發送更多數據時,我遇到了問題。
在api手冊中,您可以找到以下句子。
「當一個函數需要額外的數據時,這個數據必須發送urlencoded。應該設置HTTP頭Content-Type:application/x-www-form-urlencoded。
例如我想在api的幫助下設置用戶密碼。
SetUserPassword
設置MailStore用戶的密碼。
參數 名稱類型說明 instanceID string調用此命令的MailStore實例的唯一標識。 userName字符串MailStore用戶的用戶名。 密碼字符串MailStore用戶的密碼。
我試過這段代碼。
public function SetUserPassword()
{
$uri = 'bla.com:8474/api/invoke/SetUserPassword';
$response = Httpful::post($uri)
->authenticateWith('admin', 'password')
->addHeaders(array(
'instanceID' => 'bla',
'userName' => 'myuser',
'password' => 'mypassword'
))
->sendsType(\Httpful\Mime::FORM)
->send();
dd($response->body->error);
}
這裏是錯誤響應,我得到:
object(stdClass)[142]
public 'message' => string 'Argument instanceID is missing.' (length=31)
public 'details' => string 'System.Exception: Argument instanceID is missing.
bei #Y3c.#VGc.#X3c(#ncb #tPc, #8xe #I9f, String #GPf, NameValueCollection #P5b, Int32 #joc)
bei #Y3c.#VGc.#Slc(#LLC#Rmc, #8xe #I9f)
' (length=192)
我增加了實例ID和其他參數的標題,但是API找不到參數或值。
我認爲問題是urlencode?你可以幫我嗎?
謝謝!
非常感謝!有用! – user3382438 2014-10-10 11:17:05