function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jgoldsackjgoldsack 

Web-To-Case and WebClient

I am building custom Modules for a DotNetNuke portal I am working on, and one of the modules I am working on is using the Web-To-Case servlet. Out current version uses classic ASP to post a form to the servlet using standard form post. Because of the nature of DNN, this cannot be done using a simple form post (since cannot have 2 forms on the same page), so I am using the WebClient class, encoding the form variables in UTF-8, and then posting the values to the servlet. This all executes fine, no errors, and I get a response back from the Servlet stating there were no errors.... but the case never shows up in SalesForce, and I have not found any way to tell if it actually works.

Sample of my code:

Dim formPostData As String = ""
For Each postKey As String In Request.Form
Dim postValue As String = Request.Form(postKey)
formPostData = (formPostData + String.Format("&{0}={1}", postKey, postValue))
Next

Dim client As WebClient = New WebClient
client.Headers.Add("Content-Type", "text/html;charset=UTF-8")
Dim postByteArray() As Byte = Encoding.UTF8.GetBytes(formPostData)
Dim responseArray() As Byte = client.UploadData("http://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8", "POST", postByteArray)
Dim response As String = Encoding.ASCII.GetString(responseArray)

Select Case (response)
'Do something with the response
End Select


Is there something I am missing? The form fields that I pass are the same as are in the ASP version, so I am unsure what is going on, or how to tell if there actually is an error.
SuperfellSuperfell
That's almost certainly the wrong content-type, you should sniff the post from a browser and compare.
jgoldsackjgoldsack
I will admit that I don't have the first clue as to how to sniff the post from a browser, but thats Ok :)

This is what I have to work with from the ASP page I am basing my module off of:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<LINK href="portal.css" rel="stylesheet">
</head>
<body>
<script language="JavaScript">
<!--
Some Javascript code
// -->
</script>
<form action="http://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8" method="post" name="Form1">
....
Form itself
...
</form>
</body>
</html>

Nothing fancy or anything... basic stuff. So I am not sure how I would use that information to sniff the post... this probably isn't the place for the discussion on it, so is there a link or somethign that could explain it to me? Doing a google search brings up all sorts of things.. some of which are not very "work safe" so to speak.
jgoldsackjgoldsack
On another note, what kind of response does the servlet give it it is an error?

This is the response I get:

Your request has been queued.
Record Information:
type: Help Desk
blah1: SUP - Support
orgid: blah_origid
status: New
external: 1
retURL: ?TYPE=SUCCESS
reason: New problem
submit: Submit Query
PhoneNumber: 162
blah2: SUPPORT - Helpdesk / Ongoing Support
description: Portal Test
email: someone@somewhere.com
subject: Test
name: Me
priority: Low
J_HinderJ_Hinder
You might want to try it this way. You can probably omit the cookie stuff. I'm really trying to not diss the dnn stuff. It's been the bane of my existence for like 5 months now. ...must...hit...enter...key...fast...

Dim strURL As String
Dim uriString As String = "url-to-web-to-case"
Dim postData As String = "your-post-data"

Dim req As HttpWebRequest = WebRequest.Create(uriString)
req.CookieContainer = New CookieContainer
req.Method = "POST"
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)"
req.ContentType = "application/xml; charset=utf-8"
req.ContentLength = postData.Length
req.KeepAlive = True
req.Timeout = 50000
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = postData.Length

Dim encoding As New System.Text.ASCIIEncoding

Dim bytes As Byte() = encoding.GetBytes(postData)

Dim input As System.IO.Stream = req.GetRequestStream
input.Write(bytes, 0, bytes.Length)
input.Close()

Dim nsResponse As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
Dim streamResponse As Stream = nsResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim responseString As String = streamRead.ReadToEnd()
J_HinderJ_Hinder
Oh, and you need something like this up above the your namespace definition:

Imports System.Net
Imports System.Web
Imports System.IO
Imports System
jgoldsackjgoldsack
Thanks.. that worked.