相关疑难解决方法(0)

特定请求的NSErrorFailingURLStringKey(kCFErrorDomainCFNetwork错误-1017)

我写了一个帮助器类,我向服务器发出了所有请求(Rails 4.1).此帮助程序类中的大多数请求都可以正常工作,但一个特定请求始终失败.我正在使用Alamofire来满足我的要求.

这是我的助手类的一些代码:

let responseHandler = { (request: NSURLRequest, response: NSHTTPURLResponse?, object: AnyObject?, error: NSError?) -> Void in
    println("request: \(request) || response: \(response) || object: \(object) || error: \(error)")
}

// make custom request
let request = NSMutableURLRequest(URL: NSURL(string: fullPath)!)
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(["session_key": "ABC"], options: nil, error: nil)
request.HTTPMethod = "GET"
request.allHTTPHeaderFields = ["Accept": "application/json", "Content-Type": "application/json"]

Alamofire.request(request).response(responseHandler)
Run Code Online (Sandbox Code Playgroud)

这是println上面代码中该行的输出:

request: <NSMutableURLRequest: 0x1702007e0> { URL: http:/wolverine.movie-assistor.staging.c66.me/user } || response: nil || object: Optional(<>) || error: Optional(Error Domain=NSURLErrorDomain Code=-1017 "The …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ios nsjsonserialization swift alamofire

2
推荐指数
2
解决办法
2万
查看次数

带标题和数据的请求

我正在尝试将以下cURL命令转换为Python中的Request.

curl -H 'customheader: value' -H 'customheader2: value' --data "Username=user&UserPassword=pass" https://thisismyurl
Run Code Online (Sandbox Code Playgroud)

据我所知,可以获取头文件和POST数据.那么我怎么做这两个像cURL?

这就是我正在尝试的:

url = 'myurl'
headers = {'customheader': 'value', 'customheader2': 'value'}
data = 'Username=user&UserPassword=pass'

requests.get(url, headers=headers, data=data)
Run Code Online (Sandbox Code Playgroud)

哪个回报: HTTPError: HTTP 405: Method Not Allowed

如果我使用帖子: MissingArgumentError: HTTP 400: Bad Request

python curl python-requests

2
推荐指数
1
解决办法
4879
查看次数

如何将字典附加到URL作为参数?

我需要传递简单的字典:

var dictionary: [AnyHashable: Any] = [
    "a": 1,
    "b": "title",
    "c": ["a", "b"],
    "d": ["a": 1, "b": ["a", "b"]]
]
Run Code Online (Sandbox Code Playgroud)

到URL:

let url = URL(string: "http://example.com")!
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

从另一方面来说,如何从URL访问参数?

imessage中的输出:

在此输入图像描述

dictionary ios swift

2
推荐指数
2
解决办法
3886
查看次数

REST API,何时使用@PathParam,@ QueryParam,@ RequestBody和/或@RequestHeader

如果在何时/何时不使用上述将信息传递给REST调用的方法,我一直试图找到答案.

我一直在寻找各地,但每个帖子只讨论两种列出的方法之间的差异,或3,而不是所有4.

java rest spring restful-architecture spring-boot

2
推荐指数
1
解决办法
4156
查看次数

Jquery .ajax获取请求总是失败

除了失败之外我无法做出此要求.我使用curl和web开发人员工具栏来检查创建的URL,WD总是说响应正确地返回200.我已经尝试将内容类型更改为text,octet-stream并将其注释掉.我还采用了JSON响应并使用JSONLint对其进行了验证.

我正在使用的代码就是这个;

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <link rel="stylesheet" type="text/css" href="css/testing.css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
    <script type="text/javascript">
    $(function(){
        $("body").append("<p>Testing.....</p>");
        var test= {latitude:"37.0205",longitude:"-7.969141667",startDate:"09-01-2014",endDate:"09-02-2014"};
        var url="<hidden>";

        $.ajax({
            url : url,
            type: "GET",
            data : test,
            dataType:"json",
            contentType:"application/json",
            success: function(data,status)
            {
                $("body").append("<p>Success"+JSON.stringify(data)+"</p>");
                $("body").append("<p>Success"+status+"</p>");
            },
            error: function (jqXhr,textStatus,errorThrown)
            {
                $("body").append("<p>Failure " + JSON.stringify(jqXhr)+"----- "+ textStatus+ "----- "+ errorThrown+"</p>");
            }
        });
        $("body").append("<p>input"+JSON.stringify(test)+"</p>");
    });
    </script>
</head>
<body>
    <h1>Weather test</h1>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我在Web浏览器中从错误函数输出的是"Failure {"readyState":0,"responseText":"","status":0,"statusText":"error"} -----错误--- - "

标题是形式,

HTTP/1.1 200 OK Cache-Control:private,max-age = 0服务器:Microsoft-IIS/7.5 X-AspNet-Version:4.0.30319 X-Powered-By:ASP.NET日期:星期五,2014年10月3日11: …

jquery json http

1
推荐指数
1
解决办法
1401
查看次数

使用 RESTClient for firefox 插件将数据发布到 REST API

我正在使用 RESTClient for firefox 插件来测试 REST API,如果我将请求正文和方法设置为 GET,我设置了一些可以正常工作的标头,我无法通过我的 PHP 应用程序访问数据,但标头可用

**Request headers**   
   Content-Type : application/json

**Request Body**  

   [
   {
    "data1" : "value1",
    "data2" : "value2",
    "data3" : 1
    }
   ]
Run Code Online (Sandbox Code Playgroud)

如何正确设置请求正文?

rest post firefox-addon

0
推荐指数
1
解决办法
2万
查看次数

如何在 Javascript/NodeJS 中将两个参数传递给 API“获取”请求

我有一个 React 组件,它必须对 MongoDB 数据库执行带有两个参数的 find({}) 查询。

const likes = await Likes.find({ postId: postId, userId: userId }).exec()
Run Code Online (Sandbox Code Playgroud)

由于 Mongo 代码只能在服务器上运行,所以我必须进行 API 调用(我正在使用 NextJS)。这个API调用显然是一个GET请求。如何使用 SWR(或 fetch)将“postId”和“userId”传递给获取请求?

我试图将它们作为对象通过“身体”传递,但我认为这根本不是正确的方法。

const likesPerUser = {
    postId: postId,
    userId: userId
}

const docs = await fetch('/api/likes/user', {
    method: 'GET',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
        },
    body: JSON.stringify(likesPerUser),
})
Run Code Online (Sandbox Code Playgroud)

我无权访问 URL 查询字符串

我有一种感觉,我可能有点跑题了。任何帮助将非常感激。干杯,马特

mongodb node.js next.js swr

0
推荐指数
1
解决办法
2万
查看次数

-8
推荐指数
1
解决办法
227
查看次数