INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Hi, I need your help. Should I translate this code from c # to FOXPRO. Can you help me please

Hi, I need your help. Should I translate this code from c # to FOXPRO. Can you help me please

Hi, I need your help. Should I translate this code from c # to FOXPRO. Can you help me please

(OP)

Hi, I need your help. Should I translate this code from c # to FOXPRO. Can you help me please

//Creo la request per creare un nuovo marker
string url = "https://ws.ar.pikkart.com/cms/markers";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

//Imposto il content-type
webRequest.ContentType = "text/html";

//Come metodo specifico POST, che in http indica una insert
webRequest.Method = "POST”;


string requestBody = " {"name": "my marker name", "brandId": 372, "cntId": 9725, "width":1.0, "publishedFrom":"Fri, 2 Sep 2016 GMT", "publishedFrom":"Fri, 9 Sep 2016 GMT", "imageStreamName":"myImageFileName" } ";


//Creo una stringa contenente la data e l’ora odierna in formato RFC1123, utilizzando il timezone UTC
string date = DateTime.UtcNow.ToString("R");

//Imposto l’header “Date” della richiesta
webRequest.Headers.Add("Date ", date);

//Imposto l’header “Authorization” della richiesta
webRequest.Headers.Add("Authorization", publicKey + ":" + CreateSignature(webRequest.Method, requestBody, privateKey, date, “/cms/markers”));


//Se la richiesta non ha come metodo GET, probabilmente ho un requestBody da inviare, quindi imposto lo stream della richiesta con il contenuto (requestBody) che voglio inviare
if (webRequest.Method != "GET")
{
StreamWriter streamWriter = new StreamWriter(webRequest.GetRequestStream());
streamWriter.Write(requestBody);
streamWriter.Flush();
streamWriter.Close();
}

//Invio la richiesta al server
string result = "";
HttpWebResponse httpResponse = (HttpWebResponse)webRequest.GetResponse();

//Leggo il contenuto della risposta del server
using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
result = streamReader.ReadToEnd();

//Se la risposta ha codice diverso da 200 (HttpStatusCode.OK in C#) si tratta di un errore http
if (httpResponse.StatusCode != HttpStatusCode.OK)
throw new Exception(result);

//A questo punto nella stringa result ho il contenuto della risposta, es:
{"id":8472, "name":"my marker name", "brandId":958, "cntId":1256, "cntType":1, "parentCntId":0, "crsId":"2_405", "width":1.0, "imageUrl":"http://ar.pikkart.com/markers/sample_marker.jpg", "publishedFrom":"2016-09-02T00:00:00Z", "publishedTo":"2016-09-09T00:00:00Z" }













public string CreateSignature(string requestMethod, string requestBody, string privateKey, string requestDate, string requestPath)
{
string contentMD5 = GetMd5Hash(requestBody);
string stringToSign = GetStringToSign(requestMethod, contentMD5, requestDate, requestPath);
byte[] sha1Bytes = Encoding.UTF8.GetBytes(stringToSign);
byte[] key = Encoding.UTF8.GetBytes(privateKey);
byte[] hashedKey = SHA1.Create().ComputeHash(key);
HMACSHA1 hmac = new HMACSHA1(hashedKey);
byte[] hashedBytes = hmac.ComputeHash(sha1Bytes);
return System.Convert.ToBase64String(hashedBytes);
}

public GetStringToSign(string requestMethod, string contentMD5, string requestDate, string requestPath)
{
return string.Format("{0}|{1}|{2}|{3}", requestMethod, contentMD5, requestDate, requestPath);
}

RE: Hi, I need your help. Should I translate this code from c # to FOXPRO. Can you help me please

This question is probably more appropriate in forum184: Microsoft: Visual FoxPro.

While the example code deals with web methids and therefore may have some relation to XML, the issue at this point is that of refactoring C# and .Net into Foxpro.

Tom Morrison
Hill Country Software

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close