Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试上载文件时,Rest客户端(Ruby)未设置cookie_Ruby_Http_Rest_Cookies_Rest Client - Fatal编程技术网

尝试上载文件时,Rest客户端(Ruby)未设置cookie

尝试上载文件时,Rest客户端(Ruby)未设置cookie,ruby,http,rest,cookies,rest-client,Ruby,Http,Rest,Cookies,Rest Client,如果我尝试使用上述代码发布文件,那么发送的请求将永远不会设置标题Cookie、用户代理、X-SESSION-ID。。。我用wireshark 我做错了什么?RestClient在检测到文件并将剩余参数视为多部分请求中的其他部分时,会尝试变得聪明。因此,您只需要将内容从标题中分离出来,将其更改为散列 试试这个: require 'rubygems' require 'rest_client' response = RestClient.post "URL",

如果我尝试使用上述代码发布文件,那么发送的请求将永远不会设置
标题
Cookie、用户代理、X-SESSION-ID。。。我用
wireshark


我做错了什么?

RestClient在检测到文件并将剩余参数视为多部分请求中的其他部分时,会尝试变得聪明。因此,您只需要将内容从标题中分离出来,将其更改为散列

试试这个:

require 'rubygems'
require 'rest_client'
response = RestClient.post "URL",
                              "myfile" => File.new("/path/to/file"),
                              "Cookie" => "Name=michal",
                              "X-SESSION-ID" => "dsafasdfadsfadsfasfdadf",
                              "User-Agent" => "UNknow",
                              "connection" => "Keep-Alive"
response = RestClient.post "URL",
                           {"myfile" => File.new("/path/to/file")},
                           "Cookie" => "Name=michal",
                           "X-SESSION-ID" => "dsafasdfadsfadsfasfdadf",
                           "User-Agent" => "UNknow",
                           "connection" => "Keep-Alive"