
14

SAP ABAP HTTP Request Post Method using a REST API Call
source link: https://answers.sap.com/questions/13755337/sap-abap-http-request-post-method-using-a-rest-api.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Hi Expers,
Our company wants to integrate with a non-SAP product. We've done the GET methods, but we're having trouble with the POST methods. We need to send json data via rest api.The example code shared with us is as follows. I want to transform this code blocks to ABAP language.
static void Upload(String url, String path_locator, String subfolder, String file, String token) { string requestUrl = string.Format("{0}/RestServices/UploadFile/{1}/{2}/{3}", url, Base64Encode(path_locator), Base64Encode(subfolder), Base64Encode(System.IO.Path.GetFileName(file)), token); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl); request.Method = "POST"; request.ContentType = "application/octet-stream"; // txtFileName contains the name of the file to upload. byte[] fileToSend = File.ReadAllBytes(file); request.ContentLength = fileToSend.Length; using (Stream requestStream = request.GetRequestStream()) { // Send the file as body request. requestStream.Write(fileToSend, 0, fileToSend.Length); requestStream.Close(); } using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) Console.WriteLine("HTTP/{0} {1} {2}", response.ProtocolVersion, (int)response.StatusCode, response.StatusDescription); }
Thank you all.
</div
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK