Send JSON POST request with PHP

You can use CURL for this purpose see the example code: $url = “your url”; $content = json_encode(“your data to be sent”); $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-type: application/json”)); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $content); $json_response = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ( $status != 201 ) { … Read more

Model always null on XML POST

Two things: You don’t need quotes “” around the content type and accept header values in Fiddler: User-Agent: Fiddler Content-Type: application/xml Accept: application/xml Web API uses the DataContractSerializer by default for xml serialization. So you need to include your type’s namespace in your xml: <TestModel xmlns=”http://schemas.datacontract.org/2004/07/YourMvcApp.YourNameSpace”> <Output>Sito</Output> </TestModel> Or you can configure Web API to … Read more

ASP.NET File Upload

1.Create Uploadfile.aspx, code as below: <%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Uploadfile.aspx.cs” Inherits=”Uploadfile” %> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml”> <head runat=”server”> <title>File Upload Control</title> </head> <body> <form id=”form1″ runat=”server”> <div> <asp:FileUpload runat=”server” ID=”fuSample” /> <asp:Button runat=”server” ID=”btnUpload” Text=”Upload” onclick=”btnUpload_Click” /> <asp:Label runat=”server” ID=”lblMessage” Text=””></asp:Label> </div> </form> </body> </html> 2.create Uploadfile.aspx.cs, code as … Read more

Sending Files using HTTP POST in c# [closed]

You can try the following code: public void PostMultipleFiles(string url, string[] files) { string boundary = “—————————-” + DateTime.Now.Ticks.ToString(“x”); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = “multipart/form-data; boundary=” + boundary; httpWebRequest.Method = “POST”; httpWebRequest.KeepAlive = true; httpWebRequest.Credentials = System.Net.CredentialCache.DefaultCredentials; Stream memStream = new System.IO.MemoryStream(); byte[] boundarybytes =System.Text.Encoding.ASCII.GetBytes(“\r\n–” + boundary +”\r\n”); string formdataTemplate = “\r\n–” + boundary … Read more

How to Get the HTTP Post data in C#?

This code will list out all the form variables that are being sent in a POST. This way you can see if you have the proper names of the post values. string[] keys = Request.Form.AllKeys; for (int i= 0; i < keys.Length; i++) { Response.Write(keys[i] + “: ” + Request.Form[keys[i]] + “<br>”); }

How can I read the data received in application/x-www-form-urlencoded format on Node server?

If you are using Express.js v4.16+ as Node.js web application framework: import express from “express”; app.use(bodyParser.json()); // support json encoded bodies app.use(express.urlencoded({ extended: true })); // support encoded bodies // With body-parser configured, now create our route. We can grab POST // parameters using req.body.variable_name // POST http://localhost:8080/api/books // parameters sent with app.post(‘/api/books’, function(req, res) … Read more

HTTP POST request in Inno Setup Script

Based on jsobo advice of using WinHTTP library, I came with this very simple code that does the trick. Say, you want to send serial number for verification just before the actual installation starts. In the Code section, put: procedure CurStepChanged(CurStep: TSetupStep); var WinHttpReq: Variant; begin if CurStep = ssInstall then begin if AutoCheckRadioButton.Checked = … Read more

How to upload multipart form data and image to server in android?

If like me you were struggling with multipart upload. Here’s a solution using 95% of code from this Android snippet. public String multipartRequest(String urlTo, Map<String, String> parmas, String filepath, String filefield, String fileMimeType) throws CustomException { HttpURLConnection connection = null; DataOutputStream outputStream = null; InputStream inputStream = null; String twoHyphens = “–“; String boundary = … Read more

XMLHttpRequest to Post HTML Form

The POST string format is the following: name=value&name2=value2&name3=value3 So you have to grab all names, their values and put them into that format. You can either iterate all input elements or get specific ones by calling document.getElementById(). Warning: You have to use encodeURIComponent() for all names and especially for the values so that possible & … Read more