无法在浏览器中手动访问ASMX Web服务,但它可以使用jQuery(Can't access ASMX web service manually in browser but it works using jQuery)
我是JQuery和Web Services的新手。 我的问题是(在下面的代码中),为什么url:“WebService1.asmx / WebMethod”通过这个JQuery代码工作,但如果我直接在浏览器中输入该URL,它说无法找到路径? 我必须在浏览器中手动单击服务的“调用”按钮才能调用该方法,然后导航到WebService1.asmx / WebMethod。
$(document).ready(function () { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "WebService1.asmx/WebMethod", data: "{}", dataType: "json", success: function (msg) { alert(msg.d); }, error: function (errormessage) { alert("got an error"); } }); });
I'm new to JQuery and Web Services. My question is (in the following code), why does url: "WebService1.asmx/WebMethod" work through this JQuery code but if I type that URL directly in my browser, it says the path cannot be found? I have to manually click on the "Invoke" button for the service in the browser in order to call the method and then it navigates to WebService1.asmx/WebMethod.
$(document).ready(function () { $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "WebService1.asmx/WebMethod", data: "{}", dataType: "json", success: function (msg) { alert(msg.d); }, error: function (errormessage) { alert("got an error"); } }); });
原文:
最满意答案
let des = data.description as NSString let dataAsString = des.substringWithRange(NSMakeRange(1, data.description.characters.count-2)) var value = UInt8(0) data.getBytes(&value, range: NSMakeRange(0, dataAsString.characters.count/2)) print(value)
let des = data.description as NSString let dataAsString = des.substringWithRange(NSMakeRange(1, data.description.characters.count-2)) var value = UInt8(0) data.getBytes(&value, range: NSMakeRange(0, dataAsString.characters.count/2)) print(value)
相关问答
更多-
使用NSKeyedArchiver和NSData通过蓝牙发送UIImage(Using NSKeyedArchiver and NSData to send UIImage over bluetooth)[2023-12-08]
您无法存档这样的UIImage实例。 您必须首先创建外部表示,如PNG或JPG。 你可以使用例如UIImagePNGRepresentation()函数来做到这一点。 它将返回一个NSData实例,其中包含PNG格式的压缩图像。 该NSData实例可以与NSArchiving一起使用。 You cannot archive UIImage instances like that. You will have to create an external representation first, like P ... -
当您要以这种方式将变量的指针作为参数发送时,变量需要是可变的(即,使用var声明),因为接收函数或方法将能够直接修改变量。 你想要的代码是: var random = NSInteger(arc4random_uniform(99) + 1) //(1-100) let data = NSData(bytes: &random, length: 3) 您可以在使用Swift with Cocoa和Objective-C:与C API交互时阅读更多关于使用UnsafePointer
。 When ... -
蓝牙错误(Error with bluetooth)[2023-02-17]
问题是您在onCreate中注册接收器,它应该在onResume 。 这是发生的事情: 您的活动开始:接收者已注册; 您移动到另一个屏幕或屏幕被锁定:接收器未注册; 你回到活动:接收器仍未注册; 移动到另一个屏幕:您尝试取消注册接收器但它没有注册。 所以要解决这个问题,尝试将接收者注册移动到onResume如果可以的话。 如果你不能只在try/catch语句中包装该调用: @Override protected void onPause() { // TODO Auto-generated meth ... -
如何将NSDictionary转换为NSData,反之亦然?(How can I convert NSDictionary to NSData and vice versa?)[2019-11-22]
NSDictionary - > NSData: NSData *myData = [NSKeyedArchiver archivedDataWithRootObject:myDictionary]; NSData - > NSDictionary: NSDictionary *myDictionary = (NSDictionary*) [NSKeyedUnarchiver unarchiveObjectWithData:myData]; NSDictionary -> NSData: NSData ... -
请注意,您的manufacturerData变量的类型应该是NSData ,而不是id 。 查看NSData的文档。 length属性的返回类型是什么? 现在看看你正在使用的类型。 看到不同? 始终使用正确的数据类型。 您也可以使用subdataWithRange:方法而不是使用字节。 NSData *manufacturerData = [advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey]; if (manufact ...
-
尝试使用单字节值的数组创建数据。 const uint8_t bytes[] = {0xDE}; NSData *data = [NSData dataWithBytes:bytes length:sizeof(bytes)]; 这是创建任意常量数据的有用方法。 对于更多字节, const uint8_t bytes[] = {0x01,0x02,0x03,0x04,0x05}; NSData *data = [NSData dataWithBytes:bytes length:sizeof(bytes) ...
-
这与NSString(十六进制)到字节非常相似。 如果删除多余的标点符号,那么答案将对您有用。 This is extremely similar to NSString (hex) to bytes. The answer there will work for you if you remove the excess punctuation.
-
没有。 + (id)dataWithBytes:(const void *)bytes length:(NSUInteger)length 这个方法只需要2个参数:void指向内存中的字节流的指针,以及从这个字节流中获取NSData对象的数量。 与其他任何方法一样,这种方法没有线索,也不在意,你如何得到这个字节流,当然不知道UTF8String的任何内容,它只关心数据类型,它们与方法签名相匹配。 Matthias解释说,关于如何确定字符串长度的想法也是错误的。 使用strlen C函数。 此函数检查字符串 ...
-
从NSData创建ENUM(Create ENUM from NSData)[2022-04-16]
你可以这样做,只要你有一组预定义的消息可能值: import Foundation let data = NSData(bytes: [0xa2, 0x12] as [UInt8], length: 2) enum Data: UInt16 { case Init = 0x12a2 case Opened = 0x12a1 case AlreadyOpened = 0x13a1 case Finished = 0x12a3 } func convert(data: NSData) ... -
NSData从蓝牙到整数(NSData from bluetooth to integer)[2023-08-08]
let des = data.description as NSString let dataAsString = des.substringWithRange(NSMakeRange(1, data.description.characters.count-2)) var value = UInt8(0) data.getBytes(&value, range: NSMakeRange(0, dataAsString.characte ...