- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的用户输入收件人地址(街道地址而非电子邮件)。我需要通过 USPS 验证它,以便我知道它实际上是一个地址。
我现在正在研究他们的 API,我想我理解它,但我不确定如何使用 objective-c 来实现它。
它几乎是这样工作的:
这是他们构造的 XML 请求之一的示例:
http://SERVERNAME/ShippingAPITest.dll?API=Verify&XML=<AddressValidateRequest% 20USERID="xxxxxxx"><Address ID="0"><Address1></Address1>
<Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State> <Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
有点乱码,但已分解:
http://SERVERNAME/ShippingAPITest.dll?API=Verify&XML=
<AddressValidateRequest% 20USERID="xxxxxxx">
<Address ID="0">
<Address1></Address1>
<Address2>6406 Ivy Lane</Address2>
<City>Greenbelt</City>
<State>MD</State>
<Zip5></Zip5>
<Zip4></Zip4>
</Address>
</AddressValidateRequest>
我的第一个想法似乎很明显,但也许有更好的方法来实现它。由于 XML 提要很短,我是否应该通过简单地按照以下方式进行构建:
NSString *request = [NSString stringWithFormat:@"......"]
按照上面发布的行填写和格式化的地方。
第二个问题是如何正确地将其发送到服务器?
我只是创建一个 NSURL 请求,并将 URL 作为构造的 XML 字符串?
这是我所拥有的,但我一直发现 URL 构造错误:
- (void)verifyAddress:(Recipient*)_recipient {
NSURL *_url = [NSURL URLWithString:@"http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<AddressValidateRequest%20USERID=\"********\"><Address ID=\"0\"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>"];
// Create the request.
NSURLRequest *theRequest=[NSURLRequest requestWithURL:_url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [NSMutableData data];
NSString* newStr = [[NSString alloc] initWithData:receivedData
encoding:NSUTF8StringEncoding];
NSLog(@"the response '%@'", newStr);
} else {
// Inform the user that the connection failed.
NSLog(@"error");
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// This method is called when the server has determined that it
// has enough information to create the NSURLResponse.
// It can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.
// receivedData is an instance variable declared elsewhere.
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// Append the new data to receivedData.
// receivedData is an instance variable declared elsewhere.
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
// inform the user
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString* newStr = [[NSString alloc] initWithData:receivedData
encoding:NSUTF8StringEncoding];
NSLog(@"the response '%@'", newStr);
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
}
我收到以下错误:
Connection failed! Error - bad URL (null)
我现在唯一的问题是,就 NSURLConnection 而言,我是否一切正常?我可以玩弄 URL,我只是想确保我的实现没问题,这样我就不会原地踏步了。 :P
最佳答案
您的 URL 中有 % 20
。它应该是 %20
(没有空格)。
可能还有其他问题,但这是一个很容易发现的问题。如果您收到错误消息,您需要编辑您的问题并粘贴确切错误消息。
此外,您可能会考虑使用 Apple 的 NSURLRequest
和 NSURLConnection
类,因为可能会有更多人熟悉它们,因此您可能更容易找到帮助。
关于objective-c - 街道地址验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9528410/
我正在尝试使用 html5 创建一个世界,或者更确切地说以第一人称视角创建一条街道,而不使用 WebGL。 不幸的是,我找不到任何可以使用的引擎。有谁知道可以做到这一点的引擎,还是我必须自己编写引擎?
在我的 Android 应用程序中,我包含了谷歌地图。现在我想获取有关您周围地区的信息。例如,你是在公园/森林/海滩……所以我基本上想要一个用“水”回答输入坐标 53°33'40.9"N 10°00'
在 9535 上发出的 HERE 自动完成 API 请求返回 5 个结果,这些结果都与结果类型 street 匹配,而不是像 Google 那样匹配 postalCode默认情况下的 map 。例如
我正在考虑一个项目,我需要标题中描述的信息。 Google Maps API 是否提供此类信息,或者有人知道如何获取这些信息吗? 项目将使用 PHP、HTML 和 Javascript 完成。 最佳答
如果地址可以由子元素组成:Street、City、State、PostalCode...您如何允许此 XML: Somestreet zip
有没有办法使用 Google Maps API V3 突出显示指定的道路或街道? 这是我想要获取的示例(来自在谷歌中搜索某个地方的图像):example 样式化 map 不能满足我的要求,因为它适用于
我想创建一个应用程序来跟踪安装我的应用程序的用户,因此我有以下用于跟踪的代码,该代码运行良好,但它只会返回城市名称。但我需要完整的详细信息,例如街道名称、城市,等等。 public class
我正在创建一项服务,用户可以在其中访问世界任何地方的地址。首先,我认为 Google Places API 会很高兴,但看看这张图片(下图),问题是如何以正确的顺序过滤掉国家、城镇、街道地址。首先,我
如何将 ESRI 街道 map ( https://leaflet-extras.github.io/leaflet-providers/preview/#filter=Esri.WorldStree
一个简短的问题,希望有人能解答: 如何使用 Here Android SDK Premium 导航通过 DIR_NO_CARS、NO_THROUGH_TRAFFIC、DIR_NO_TRUCKS 属性的
我正在开发 Google 地点自动完成服务,我需要过滤特定于国家/地区的地点! 引用网站:-- https://www.grubhub.com (特定国家/地区、城邦-邮政编码) 我找到了一个例子:-
我有两个 PCollections:一个从 Pub/Sub 中提取信息,另一个从 CSV 文件中提取数据。在每个管道中进行一些不同的转换之后,我想将两者合并到它们共享的公共(public) key “
DSMOD 似乎没有能力更新用户的这部分 AD 属性(街道、邮政信箱、城市、州、邮政编码)。有没有我可以从 powershell 或 cmd 运行的命令行替代方案? 动机:我正在尝试用特定的用户信息填
DSMOD 似乎没有能力更新用户的这部分 AD 属性(街道、邮政信箱、城市、州、邮政编码)。有没有我可以从 powershell 或 cmd 运行的命令行替代方案? 动机:我正在尝试用特定的用户信息填
我想在 OSM 中的两点之间画一条线,但我找不到任何可以帮助我的东西。像 googlemap 中的 Polyline 之类的东西。 public class MainActivity extends
我正在使用 PKPaymentAuthorizationViewController 及其委托(delegate)方法集成 Apple Pay。当用户更改地址时,将触发以下委托(delegate)方法
我需要使用 Xamarin Forms/Android 的 Intent 以编程方式打开 Android 联系人应用程序。当“添加新联系人” Activity/屏幕出现时,我想用以下字段预先填充它:
我是一名优秀的程序员,十分优秀!