put

How to create a GET, POST, and PUT request in Swift?

半腔热情 提交于 2019-12-03 16:43:53
I can connect to a server synchronously with this code snippet in swift. let URL: NSURL = NSURL(string: "http://someserver.com)! let InfoJSON: NSData? = NSData(contentsOfURL: URL) let JsonInfo: NSString = NSString(data:InfoJSON!, encoding: NSUTF8StringEncoding)! let GameListAttributions: NSArray = NSJSONSerialization.JSONObjectWithData(InfoJSON!, options: .allZeros, error: nil)! as NSArray This is only good for receiving information all at once, but how would I use a GET, POST, and PUT with Swift. No matter how much I search I can't find a good tutorial or example on how to execute these. let

Error: C# The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

纵饮孤独 提交于 2019-12-03 10:47:36
问题 I'm trying to make a request via SSL. The certificate is already installed on the machine and it works via browser. I am using this request: System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] data = encoding.GetBytes(request.Content.OuterXml.ToString()); string password = "XXXX"; X509Certificate2 cert = new X509Certificate2("c:\\zzzz.p12", password); string key = cert.GetPublicKeyString(); string certData = Encoding.ASCII.GetString(cert.Export(X509ContentType.Cert));

POSIX error 12 (“Cannot allocate memory”) while uploading files from an iPhone

↘锁芯ラ 提交于 2019-12-03 07:27:01
I'm working on an iPhone application that involves uploading full photos from the camera (generally between 1.5 to 2.0 MB each) as well as their thumbnails (much smaller) to Amazon S3. The thumbnails always successfully upload, but sometimes the full images don't, and when they fail, they fail with POSIX error code 12, aka ENOMEM. However, I've added debug code to print the amount of free memory when the error happens, and there's always quite a bit free, usually more than 100 MB. Furthermore, the error crops up more often when the upload is happening over 3G and less when it's over wifi --

Ruby: PUT Request with JSON body?

牧云@^-^@ 提交于 2019-12-03 07:04:54
问题 I need to create an HTTP PUT request using ruby. The request has a JSON body I was able to generate the JSON body using: require 'rubygems' require 'json' jsonbody = JSON.generate["message"=>"test","user"=>"user1"] I need to send this PUT request to the url: require 'open-uri' url = URI.parse('http://www.data.com?access_token=123') Can someone please tell me how I can do this in Ruby? 回答1: Using restclient ( gem install rest-client ) like this: require 'rubygems' require 'rest_client' require

Why don't browsers support PUT and DELETE requests and when will they?

元气小坏坏 提交于 2019-12-03 06:32:20
问题 I'm seeing many frameworks recently that have decided to "fake" PUT and DELETE requests. Like Ruby on Rails. They seem to be waiting for browsers to catch up. Are they waiting in vain? Is this even slated to be implemented anywhere? 回答1: Browsers do support PUT and DELETE , but it's HTML that doesn't. For example, a browser will initiate a PUT request via Javascript (AJAX), but not via HTML <form> submission. This is because HTML 4.01 and the final W3C HTML 5.0 spec both say that the only

Unable to make PUT/POST/DELETE HTTP Call using CORS in JQuery 1.6.4

牧云@^-^@ 提交于 2019-12-03 05:10:44
问题 So, I can successfully make a GET call to my service using CORS. However, something must be going wrong at the preflight level for the POST, PUT, and DELETE operations. However, from what I can tell, the header responses my server is returning in response to the OPTIONS query are correct and match those described in Here is my javascript code, using $.ajax in JQuery 1.6.4. $.ajax({ url: 'http://myhome:8080/TaskApproval/resources/tasks/2', context: this, data: '<?xml version="1.0" encoding=

should I use PUT method for update, if I also update a timestamp attribute

给你一囗甜甜゛ 提交于 2019-12-03 03:41:53
问题 To be more precise: According to rest style, it's generally assummed that POST, GET, PUT, and DELETE http methods should be used for CREATE, READ, UPDATE and DELETE (CRUD) operations. In fact, if we stick to the http methods definition the thing might not be so clear In this article it's explained that: In a nutshell: use PUT if and only if you know both the URL where the resource will live, and the entirety of the contents of the resource. Otherwise, use POST. Mainly because PUT is a much

Java map.get(key) - automatically do put(key) and return if key doesn't exist?

谁说我不能喝 提交于 2019-12-03 03:25:42
问题 I am sick of the following pattern: value = map.get(key); if (value == null) { value = new Object(); map.put(key, value); } This example only scratches the surface of the extra code to be written when you have nested maps to represent a multi-dimensional structure. I'm sure something somewhere exists to avoid this, but my Googling efforts yielded nothing relevant. Any suggestions? 回答1: The java.util.concurrent.ConcurrentMap and from Java 8 Java.util.Map has putIfAbsent(K key, V value) which

X-HTTP-Method-Override in jQuery?

*爱你&永不变心* 提交于 2019-12-03 03:13:43
问题 How can I do an X-HTTP-Method-Override for an ajax request in jQuery? 回答1: With 1.5 you can now pass in a headers option: $.ajax({ headers: { 'X-HTTP-Method-Override': 'DELETE' }, method: 'GET' // more parameters... }); This is set before 'beforeSend' is called, so it could still get overwritten. See http://api.jquery.com/jQuery.ajax/ -- fixed incorrect syntax (wouldn't let me save with less than 6 character edit, so writing this message 回答2: You could set custom headers when performing an

PHP curl 实现RESTful PUT DELETE 实例

纵饮孤独 提交于 2019-12-03 03:09:04
客户端 client.php <?php //PUT $curl_handle = curl_init (); // Set default options. curl_setopt ( $curl_handle, CURLOPT_URL, 'http://my.focus.cn/test/socket.php'); curl_setopt ( $curl_handle, CURLOPT_FILETIME, true ); curl_setopt ( $curl_handle, CURLOPT_FRESH_CONNECT, false ); curl_setopt ( $curl_handle, CURLOPT_HEADER, true ); curl_setopt ( $curl_handle, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $curl_handle, CURLOPT_TIMEOUT, 5184000 ); curl_setopt ( $curl_handle, CURLOPT_CONNECTTIMEOUT, 120 ); curl_setopt ( $curl_handle, CURLOPT_NOSIGNAL, true ); curl_setopt ( $curl_handle, CURLOPT_HEADER,