2017-11-07 1 views
0

테이블 저장소 서비스에서 인세 트 테이블 엔티티 REST API를 실행하려고하지만 작동하지 않습니다.Azure 테이블 서비스 REST API 오류

나는 this doc를 언급했다. 내 요청 코드가 여기에있다

,

<?php 
// storage account name 
$account = "mystgaccount"; 
$tablestoragename = "mytablename"; 
$accessKey = "myaccesskey"; 
$date = gmdate('D, d M Y H:i:s T',time()); 
$api_version = "2015-12-11"; 
$url = "https://$account.table.core.windows.net/$tablestoragename"; 
$method = "POST"; 
$body = '{"Address":"MountainView","Age":23,"AmountDue":200.23,"[email protected]":"Edm.Guid","CustomerCode":"c9da6455-213d-42c9-9a793e9149a57833","[email protected]":"Edm.DateTime","CustomerSince":"2008-0710T00:00:00","IsActive":true,"[email protected]":"Edm.Int64","NumberOfOrders":"255","PartitionKey":"mypartitionkey","RowKey":"myrowkey"}'; 

$stringToSign = [ 
// VERB 
$method, 
// Content-MD5 
'', 
// Content-Type 
'', 
// Date 
$date, 
]; 

$stringToSign = array_merge($stringToSign, ["/$account/$tablestoragename"]); 
$stringToSign = implode("\n", $stringToSign); 
$signature = base64_encode(hash_hmac('sha256', $stringToSign, base64_decode($accessKey), true)); 

$headers = [ 
"x-ms-date:{$date}", 
"x-ms-version:$api_version", 
"Authorization:SharedKey $account:{$signature}", 
"Content-Type: application/json", 
]; 

$ch = curl_init(); 

$options = array(
CURLOPT_URL => $url, 
CURLOPT_HTTPHEADER => $headers, 
CURLOPT_CUSTOMREQUEST => $method, 
CURLOPT_SSL_VERIFYPEER => FALSE, 
CURLOPT_RETURNTRANSFER => TRUE, 
CURLOPT_POSTFIELDS => http_build_query($body), 
); 

curl_setopt_array($ch, $proxy_options); 
curl_setopt_array($ch, $options); 

$response = curl_exec($ch); 
var_dump($response); 
echo curl_error($ch); 
curl_close($ch); 

?> 

응답

"<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>AuthenticationFailed</m:code><m:message xml:lang="en-US">Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. 
RequestId:b93fe560-0002-0028-129a-571361000000 
Time:2017-11-07T07:34:13.3303714Z</m:message></m:error>"  

내가 관련 질문을 읽을 수는 있지만 아직 해결되지 않은 :(

당신이 어떤 아이디어가 있습니까?

+0

AuthenticationFailed : 잘못된 계정 데이터입니까? – KimKulling

+0

답장을 보내 주셔서 감사합니다, 김. 나는 나의 계좌를 확인했으나 틀린 것은 아니다. – ssk3

답변

0

이 오류의 가능한 원인은 Content-Type heade 아르 자형. 요청에이 헤더를 지정하고 있지만 $stringToSign에는 포함되어 있지 않습니다. 을 다음과 같이 변경하여 다시 시도하십시오.

$stringToSign = [ 
// VERB 
$method, 
// Content-MD5 
'', 
// Content-Type 
'application/json', 
// Date 
$date, 
]; 
+0

안녕 Gaurav, 답장을 보내 주셔서 감사합니다. Content-Type을 시그니처에 추가했지만 다른 오류가 있습니다. "요청 입력 중 하나가 유효하지 않습니다." 시체에 문제가 있다는 뜻입니까? – ssk3

+0

실수를 발견했습니다. body json은 이미 인코딩되었으므로 http_build_query가 필요하지 않습니다. 여러분, 고마워요! – ssk3