0

Here's the scenario: We have an iOS app that makes an HTTP POST request to my .NET Web API. The method that is invoked is PostPicture (below):

// POST api/blah
    [HttpPost]
    public string PostPicture(HttpRequestMessage msg)
    {
        HttpContext context = HttpContext.Current;
        etc...

As you can see, this method takes in an HttpRequestMessage. The issue I'm having is I constantly have to rely on the iOS app to make the call just to be able to pass in the HttpRequestMessage to test my .NET code.

I had the iOS developer send me the HTTP POST contents that the device (iOS) is sending to my Web API. He sent it in a text document.

Question: Is there any way to take those raw contents and basically emulate an HTTP POST request with these contents (and of course create an HttpRequestObject based on those contents) within my code?

Here's the HTTP POST contents that he sent me:

{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf370
{\fonttbl\f0\fnil\fcharset0 Menlo-Bold;\f1\fnil\fcharset0 Menlo-Regular;}
{\colortbl;\red255\green255\blue255;\red81\green112\blue255;}
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\deftab529
\pard\tx529\pardeftab529\pardirnatural

\f0\b\fs22 \cf0 \CocoaLigature0 2013-06-14 15:17:32.969 blah[11765:907] insertEntity URL: http://domain/blahWS/API/blah/PostPicture\
\pard\tx529\pardeftab529\pardirnatural

\f1\b0 \cf0 Printing description of mikeTest:\
\{\
  "imageDataBlob" : "JVBERi0xLjMKJcTl8uXrp\\/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAg\\nUiAvRmlsdGVyIC9GbG...",\
  "layer" : "0",\
  "blah" : "YES",\
  "pdf" : "JVBERi0xLjMKJcTl8uXrp\\/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAg\\nUiAvRmlsdGVyIC9GbG...",\
  "imageCount" : "3",\
  "groupID" : "1_userName",\
  "longitude" : -95.98030149945615,\
  "latitude" : 36.74866412304039,\
  "JsonData" : "[\{ \\"geometry\\" : \{\\"x\\":-95.98030149945615 , \\"y\\": 36.74866412304039\} ,\\"attributes\\":\{ \\"Feature\\" : \\"Chemical_Treatment\\",\\"Type\\" : \\"\\",\\"Prod_Name\\" : \\"\\",\\"Line_Dia\\" : \\"\\",\\"Line_Mat\\" : \\"Select\\",\\"Prspct_Fld\\" : \\"\\",\\"Comments\\" : \\"\\",\\"HTML_LINK\\":\\"http:\\/\\/subdomain.url.net\\/blahWS\\/ImageViewer\\/Display\\/1_userName_2013-06-14_15:17:02\\",\\"APP_LAT\\":\\"36.74866412304039\\",\\"APP_LONG\\":\\"-95.98030149945615\\", \\"groupID\\":\\"1_userNamep_2013-06-14_15:17:02\\"\}\}]",\
  "Timestamp" : "2013-01-01 12:12:23",\
  "username" : "_userName"\
\}\
\pard\tx529\pardeftab529\pardirnatural

\f0\b \cf2 (lldb) }
Mike Marks
  • 10,017
  • 17
  • 69
  • 128
  • 1
    I'd tackle it by using the CURL utility. http://stackoverflow.com/questions/3007253/send-post-xml-file-using-curl-command-line – chris.w.mclean Jun 15 '13 at 14:16

2 Answers2

2

You could use Fiddler to simulate a request easily using The Composer.

NOTE: The request this developer sent you looks like some RTF file rather than an actual HTTP request. You might familiarize himself that an HTTP request contains 2 parts: HTTP headers and body payload that you will need in order to perform an HTTP request.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks for the useful information. I appreciate it. I am completely unfamiliar with this territory. I will mess with Fiddler and I informed the developer of what you said. – Mike Marks Jun 14 '13 at 20:51
1

You can use the HttpClient class in .NET 4.0 and 4.5.

Rob Lyndon
  • 12,089
  • 5
  • 49
  • 74