Use SSL to talk to fedex

L

Logan

I am trying to implement talk directly to the fedex servers so i can use
there online services. I need to first establish an SSL connection then
send some information to the fedex servers and wait for and process the
response.

I have seen some code that will allow me to recieve info over ssl and some
that will allow me to send info over ssl but not both.
Thanks in advance for any help,
~Logan

I have attached the VB sample code fedex provides
----------
Private Sub Command1_Click()

qq$ = Chr$(34) 'The " character

'DNS name of FedEx server

'contact FedEx for correct server name and port

SvcAddr = "SSLserver.fedex.com"

SvcPort = 8000

SvcName = "/GatewayDC"

' Set proxy - Examine this method to set specific proxy address

WinHttpReq.SetProxy HTTPREQUEST_PROXYSETTING_DIRECT

'Specify https for Secure Sockets

RequestHeader = "https://" + SvcAddr + ":" + SvcPort + SvcName

' Open an HTTP Request.

WinHttpReq.Open "POST", RequestHeader, False

' Substitute your Company name for MyApplication

WinHttpReq.SetRequestHeader "User-Agent", "MyApplication"

WinHttpReq.SetRequestHeader "Content-type", "image/gif"

WinHttpReq.SetRequestHeader "Accept", "image/gif, image/x-xbitmap,

image/jpeg, image/pjpeg, */*"

'A simple 402 tracking transaction

APITrans = "0," + qq$ + "402" + qq$ + "29," + qq$ + "821343443862" + qq$

+ "99," + qq$ + qq$

' Send the HTTP Request.

WinHttpReq.Send APITrans

' Put status and content type into status text box.

Text1.Text = WinHttpReq.Status & " - " & WinHttpReq.StatusText

Text2.Text = WinHttpReq.ResponseText

End Sub

--------------------------
 
N

Nicholas Paldino [.NET/C# MVP]

Logan,

You can do this easily in .NET. You want to use the HttpWebRequest and
HttpWebResponse classes in the System.Net namespace. Here is that sample,
translated into .NET:

// Create a Uri builder.
UriBuilder uriBuilder = new UriBuilder("https", SvcAddr, SvcPort,
GatewayDC);

// Get the uri.
Uri uri = uriBuilder.Uri;

// Create an HttpWebRequest.
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);

// Set the method.
request.Method = "POST";

// Set the user agent.
request.UserAgent = "MyApplication";

// Set the content type.
request.ContentType = "image/gif";

// Set the accept header.
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";

// The qq.
string qq = new String(new char[]{Convert.ToChar(34)});

// The body of the request.
// You could use a StringBuilder here as well, better for lots of appending
operations to strings.
string body = "0," + qq + "402" + qq + "29," + qq + "821343443862" + qq +
"99," + qq + qq;

// Convert to bytes.
byte[] bytes = Encoding.ASCII.GetBytes(body);

// Set the content length.
request.ContentLength = bytes.Length;

// Now send the text, get the request stream.
Stream stream = request.GetRequestStream();

// Write the bytes to the stream.
stream.Write(bytes, 0, bytes.Length);

// Now get the response.
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

// You can now get the status through the Status property on
// the HttpWebResponse, and get the text of the response by calling
// GetResponseStream and getting the bytes and decoding them into unicode.

Hope this helps.
 
Top