ios - 附加图像并发布到 JSON API
<p><p>如何使用图片创建帖子并将其作为 iPhone 应用的特色图片附加?</p>
<p>我正在使用带有 <a href="http://wordpress.org/extend/plugins/json-api/" rel="noreferrer noopener nofollow">JSON API plugin</a> 的 wordpress </p>
<p>我创建帖子的网址:<-- <a href="http://wordpress.org/extend/plugins/json-api/other_notes/#2.2.-Pages-controller-methods" rel="noreferrer noopener nofollow">Reference to this</a> </p>
<pre><code>http://www.example.com/api/create_post/?nonce=eea4bb4ce5&status=publish&title=Test&content=test%20content&categories=animals
</code></pre>
<p>现在我需要将手机图库中的图片附加到此网址。我该怎么做?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个。使用 JSON POST 方法。您可以像这样附加所有参数。</p>
<pre><code>-(void)uploadImage
{
NSString *method =@"";
NSString *username = @"";
NSString *token = @"";
NSString *urlString = ;
NSMutableURLRequest *request = [[ init] autorelease];
];
;
NSMutableData *body = ;
// file
NSData *imageData = UIImageJPEGRepresentation( imageView.image, 0.8);
NSString *boundary = ;
NSString *contentType = ;
;
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
];
dataUsingEncoding:NSUTF8StringEncoding]];
//parameter username
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
];
dataUsingEncoding:NSUTF8StringEncoding]];
//parameter token
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
];
dataUsingEncoding:NSUTF8StringEncoding]];
// //parameter method
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
];
dataUsingEncoding:NSUTF8StringEncoding]];
// close form
dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
;
// now lets make the connection to the web
NSData *returnData = ;
NSString *returnString = [ initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
;
}
</code></pre>
<p>希望对您有所帮助。</p></p>
<p style="font-size: 20px;">关于ios - 附加图像并发布到 JSON API,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/10662907/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/10662907/
</a>
</p>
页:
[1]