objective c - Error when trying to send data to CouchDB database -
when try run code send data couchdb database, got error:
2015-06-04 15:30:43.426 ddd[8303:640525] requestreply: {"error":"bad_request","reason":"referer header required."}
anyway can fix this?
- (ibaction)senddatatojson:(id)sender { nsstring *post = [nsstring stringwithformat:@"--"]; nsdata *postdata = [post datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nsstring *postlength = [nsstring stringwithformat:@"%d", [postdata length]]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init]; [request seturl:[nsurl urlwithstring:@"http://127.0.0.1:5984/sgram/cc362033a500f51767fbc87efc0003ae"]]; [request sethttpmethod:@"post"]; [request setvalue:postlength forhttpheaderfield:@"content-length"]; [request sethttpbody:postdata]; nsurlresponse *requestresponse; nsdata *requesthandler = [nsurlconnection sendsynchronousrequest:request returningresponse:&requestresponse error:nil]; nsstring *requestreply = [[nsstring alloc] initwithbytes:[requesthandler bytes] length:[requesthandler length] encoding:nsasciistringencoding]; nslog(@"requestreply: %@", requestreply); }
use verb put
instead of post
.
Comments
Post a Comment