简要问题:在 Dashcode 3.0 中,我如何告诉数据源发送 POST 请求,例如:
url:
https://example.com/xml
method:
POST
HTTPBody:
<?xml version='1.0'?>
<request command='list'>
<parameter keyword='id' value='trogdor' />
</request>
Snow Leopard 中的新 Dashcode 3.0 非常棒。我对“数据源”特别感兴趣——您可以在其中提供返回 XML 或 JSON 的 URL。Dashcode 获取数据,然后允许您在响应和 UI 之间绘制连接——很像 Interface Builder。
我发现的所有示例都使用 HTTP GET 请求。但我的提要必须通过 POST 访问。DC.AjaxController 有一个“方法”属性——很容易设置为 POST。它还有一个“参数”属性——模仿基于表单的帖子。问题是,我的请求不是来自表格。我将描述我在 Objective-C 中所做的工作。我想让同样的东西像仪表板和 Safari 小部件一样工作。
NSMutableURLRequest *theRequest=[NSMutableURLRequest
requestWithURL:[NSURL URLWithString:@"https://example.com/xml"]];
[theRequest setHTTPMethod:@"POST"];
NSString *postString =
@"<?xml version='1.0'?><request command='list'><parameter keyword='id' value='trogdor' /></request>";
[theRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
可以手动完成——我不必使用 whiz-bang Dashcode 3.0 视觉连接,但这会很有趣。