weixin_33698823 2014-07-11 09:33 采纳率: 0%
浏览 307

将curl转换为js(ajax)

I want to create an API to send a photo or video to https://partner.path.com/1/moment/photo(recorded as A)

It can be done successfully by curl as the following:

curl -H 'Authorization: Bearer <ACCESS_TOKEN>' 
-F "image=@F:photo.jpg" 
-F 'data={"caption": "I like cheese!"}' 
A

However,it is failed(400 BAD_REQUEST) when sending the request by Ajax as the following:

$.ajax({
type : "POST",  
url : "A",
async : false,
data : "{"image":"@F:photo.jpg", "caption":"I like the picture", "private":true}",
dataType : 'json',
contentType : "application/json",
crossDomain : true,
beforeSend : function(xhr) {
xhr.setRequestHeader("Authorization", "Bearer 5f323a1c21a89cde270ffe78b3835d8a4bdd67c0");
},
success : function(res, textStatus) {
console.log(res);               
}
});

I think the problem maybe exist on the parameters(particularly the data parameter) when making ajax call. What is the correct format of the data parameter?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站