2014-10-11 4 views
0

내가 구름 코드의 컬 요청을 실행해야하지만 성공적으로 변환 할 수 없습니다 (귀국일 오류 코드 401 : 인증되지 않은) :변환 CURL 요청이

는 컬을 요청 형식은 :

curl --digest -u Key:Secret "http://example.com/" --form [email protected]"animage.jpg" -X PUT 

내가이 노력하고있어 :

Parse.Cloud.httpRequest({ 
    method: 'PUT', 
    url: 'http://example.com', 
    headers: { 
    'Content-Type': "application/json", 
    'Key': "xXXXXx", 
    'Secret': "xXXXXXx", 
    }, 
body: { 
    'imagepath': "http://.../photo.png" 
}, 
success: function(httpResponse) { 

    console.log(httpResponse.text); 
}, 
error: function(httpResponse) { 

    console.error('Request failed with response code ' + httpResponse.status); 
} 
}); 

[업데이트]

을 나는 시도 GET 방식으로 (어떻게 작동하는지 이해하는)이 그 통화와 함께 일하고있다 (나는 ... 구글 크롬 개발자 관리자와 인증 라인을 발견했습니다) :

Parse.Cloud.httpRequest({ 
method: 'GET', 
url: 'http://example.com', 

headers: { 
Authorization: 'Digest username="XXxxXXXX", realm="API Name", nonce="XXXxxxXXX",  uri="example.com", response="XXXxxxXXX", opaque="XXxxxxXXX", qop=auth, nc=xxXXXxx,  cnonce="XXXxxxXX"' 
}, 

success: function(httpResponse) { 

console.log(httpResponse.text); 
response.success("Okayyy!"); 
}, 
error: function(httpResponse) { 

console.error('Request failed with response code ' + httpResponse.status); 

response.error("error"); 
} 
}); 

그러나 PUT 방식의 작품을 만들 수있는 방법 .

답변

0

기본 인증을 사용하여 URL을로드하려고하는 것 같습니다. 맞으면 자격 증명을 URL의 일부로 전달할 수 있습니다.

Parse.Cloud.httpRequest({ 
    method: 'PUT', 
    url: 'http://key:[email protected]', 
    headers: { 
    'Content-Type': "application/json", 
    }, 
body: { 
    'imagepath': "http://.../photo.png" 
}, 
success: function(httpResponse) { 

    console.log(httpResponse.text); 
}, 
error: function(httpResponse) { 

    console.error('Request failed with response code ' + httpResponse.status); 
} 
}); 
+0

감사합니다. 나는 당신의 해결책을 시도했지만 나에게 400 에러 코드 (나쁜 요청)를 주었다. – oliver

+0

curl 명령이 PUT을 사용하고 있지만 코드에서 POST를 사용하고있는 것으로 나타났습니다. 코드를 변경했습니다.이 코드를 사용해보십시오. – sarvesh

+0

예이 타이포를 알아 채고 성공없이 PUT을 시도했습니다. '(응답 : "응답 코드 400으로 요청이 실패했습니다" – oliver

관련 문제