我正在将 iOS 应用程序从 Xcode4 迁移到 Xcode7 (beta 4)。对 AFNetworking 的依赖通过 Pod 自动解决。 AFNetworking 2.0 不向后兼容 AFNetworking 1.0,所以我修改了部分源代码。 Here是
下面的问题
/Api/ApiClient.m::: error: unexpected interface name 'NSData': expected expression
NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding];
^
/Api/ApiClient.m::: error: use of undeclared identifier 'callerData'
NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding];
在上面例子的第 280 行
将 NSData 替换为 NSString 会导致以下错误
原始 AFNetwork-1.0 代码如下
我尝试通过将例程替换为//1 来迁移到 AFNetwork-2.0
或//2
没有成功
最佳答案
我认为 NSData 编译器错误是一个转移注意力的问题。问题是您只为“失败”参数而不是“constructingBodyWithBlock”参数提供了一个代码块。
尝试这样的事情:
NSMutableURLRequest* request =
[ [ApiManager sharedManager]
POST:@"/v1/exec"
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{
// Code to form the body of the form is here
//NSData* callerData = [[NSData alloc] init];
NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding];
[formData appendPartWithFormData:callerData name:@"caller"];
[formData appendPartWithFileData:fontData name:@"front" fileName:@"front" mimeType:@"application/octet-stream"];
[formData appendPartWithFileData:sideData name:@"side" fileName:@"side" mimeType:@"application/octet-stream"];
}
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
// Operation success code goes here
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
// Operation failed code goes here
}
];
对于任何格式问题深表歉意 - 遇到 Markdown 问题。
关于ios - AFNetworking 2.0 POST 问题 |替换已弃用的 multipartFormRequestWithMethod :path:parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31697762/
是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou
我知道您通常应该在Rails中使用新建/创建和编辑/更新之间的链接,但我有一个情况需要其他东西。无论如何我可以实现同样的连接吗?我有一个模型表单,我希望它发布数据(类似于新View如何发布到创建操作)。这是我的表格prohibitedthisjobfrombeingsaved: 最佳答案 使用:url选项。=form_for@job,:url=>company_path,:html=>{:method=>:post/:put} 关于ruby-on-rails-rails:Howtomak
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在阅读SandiMetz的POODR,并且遇到了一个我不太了解的编码原则。这是代码:classBicycleattr_reader:size,:chain,:tire_sizedefinitialize(args={})@size=args[:size]||1@chain=args[:chain]||2@tire_size=args[:tire_size]||3post_initialize(args)endendclassMountainBike此代码将为其各自的属性输出1,2,3,4,5。我不明白的是查找方法。当一辆山地自行车被实例化时,因为它没有自己的initialize方法
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
在我的Character模型中,我添加了:字符.rbbefore_savedoself.profile_picture_url=asset_path('icon.png')end但是,对于数据库中已存在的所有角色,它们的profile_picture_url为nil。因此,我想进入控制台并遍历所有这些并进行设置。在我试过的控制台中:Character.find_eachdo|c|c.profile_picture_url=asset_path('icon.png')end但这给出了错误:NoMethodError:undefinedmethod`asset_path'formain:O
-if!request.path_info.include?'A'%{:id=>'A'}"Text"-else"Text"“文本”写了两次。我怎样才能只写一次并同时检查path_info是否包含“A”? 最佳答案 有两种方法可以做到这一点。使用部分,或使用content_forblock:如果“文本”较长,或者是一个重要的子树,您可以将其提取到一个部分。这会使您的代码变干一点。在给出的示例中,这似乎有点矫枉过正。在这种情况下更好的方法是使用content_forblock,如下所示:-if!request.path_info.inc