Cfhttp and setting the content-type for a request

Hi,
I am trying to set the content-type for a cfhttp request like this (on coldfusion 9):
<cfhttp redirect="no" method="get" timeout="120" url="http://10.0.0.1/test2.cfm">
    <cfhttpparam type="HEADER" name="Content-Type" value="application/json; charset=utf-8">
</cfhttp>
// coding on test2.cfm:
<cfset x = GetHttpRequestData()>
<cfdump var=#x#>
// Output on test2.cfm
content
[empty string]
headers
struct
Accept-Encoding
deflate, gzip, x-gzip, compress, x-compress
Connection
TE
Host
10.0.0.1:80
Proxy-Connection
close
TE
trailers, deflate, gzip, compress
User-Agent
ColdFusion
X-REWRITE-URL
http://10.0.0.1:80/test2.cfm
method
GET
protocol
HTTP/1.1
As you can see no content-type is send through. I also tried the sniffer.exe:
GET http://10.0.0.1:80/test2.cfm HTTP/1.1
Host: 127.0.0.1
Proxy-Connection: close
Connection: TE
TE: trailers, deflate, gzip, compress
User-Agent: ColdFusion
Accept-Encoding: deflate, gzip, x-gzip, compress, x-compress
Here you can also see that no content-type was passed through. The sniffer should report back
GET http://10.0.0.1:80/test2.cfm HTTP/1.1
Host: 127.0.0.1
Proxy-Connection: close
Connection: TE
TE: trailers, deflate, gzip, compress
User-Agent: ColdFusion
Accept-Encoding: deflate, gzip, x-gzip, compress, x-compress
Content-Type: application/json; charset=utf-8
But is does not, what do i need todo to set the content-type in a cfhttp request.
Kind regards,
Nebu

12Robots - are you sure about your statement that GET method requests cannot have Content-Type headers?  I don't think that that is correct.  I've always thought that it was valid (maybe unusual, but ...) and this W3C link weems to agree, especially in the context of its comment about what Content-Type means in a HEAD method request: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
The big problem with trying to get around the CFHTTP limitation by using the CGI scope is that the dash is illegal in a CF varname.
There is a custom tag called CFHTTP5 that getsaround a lot of the CFHTTP limitations, including cookie preservation across multiple requests.  I haven't used it for a long time (CF5), but it is still actively developed.  Costs $50 - http://www.cftagstore.com/tags/cfxhttp5.cfm
-reed

Similar Messages

  • The content type for office excel 2007 in jsp page and the mime-type in  we

    Hi,
    In my system MS Office 2007 is installed. I am trying to generating excel sheets from JSP page by setting the content type "application/vnd.ms-excel" in jsp page and as well as in web.xml file. I am getting the below message
    The file you are trying to open, 'xxxxxxxx.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
    Then finally the excel file is opening and displaying properly. If in my system MS Office 2003 is installed , then the above message is not coming.
    I have changed the content type according to Excel 2007 <%@ page contentType= "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" %> and in web.xml file the mime type to
    <mime-mapping>
    <extension>xlsx</extension>
    <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type>
    </mime-mapping>
    even the content type is changed according to office excel 2007 , i am getting the same above message.
    My client is asking not to display the above message. So how to prevent that message ?
    It's very great if any body reply me as soon as possible.

    Hi Akash,
    I am not using the POI. I am generating the excel sheet using the below code.
    <jsp:directive.page import="java.util.Map" />
    <jsp:directive.page import="lehman.ra.Report.ReportDefinition" />
    <jsp:directive.page import="lehman.ra.RAUtilBean" />
    <jsp:directive.page import="java.util.ArrayList" />
    <jsp:directive.page import="lehman.util.GeneralUtil" />
    <jsp:directive.page import="lehman.admin.report.AdminHtmlReportFormatter"/>
    <jsp:directive.page import="lehman.helper.irprod.IRProdHelper"/>
    <%@ page contentType= "application/vnd.ms-excel" %>
    <jsp:directive.page import="java.util.Iterator"/>
    <jsp:directive.page import="java.util.HashMap"/>
    <%
         String strTradeDate = (String) session.getAttribute("TradingDate");
         String sContextPath = request.getContextPath();
         IRProdHelper irHelper     = new IRProdHelper();
         String  sReportFormat  = "E2E";     
         String subtab1 = request.getParameter("subtab1");
         if (subtab1 == null)
              subtab1 ="";     
         Map report_Ids    = (Map) session.getAttribute("ADMIN_E2E_REPORTS");
         AdminHtmlReportFormatter formatter = new AdminHtmlReportFormatter();
         ArrayList contentData = new ArrayList();
         ArrayList headerData  = new ArrayList();
         ArrayList metaData    = new ArrayList();
         Map resultMap            = null;
         String headerString       = "";
         String contentString  = "";
         String reportId            = "";
         int titleSpan         = 5;     
         if( report_Ids!=null && report_Ids.size() > 0){
              Object oReportObj      = null;
              Iterator rowIter = report_Ids.keySet().iterator();
              RAUtilBean raUtilBean = new RAUtilBean();
              ReportDefinition rdef = new ReportDefinition();
              while ( rowIter.hasNext() ){          
                   oReportObj = rowIter.next();     
                   reportId = oReportObj.toString();
                   System.out.println("**************reportId="+reportId);     
                   resultMap  =  (HashMap) report_Ids.get(oReportObj);
                   if(resultMap == null )
                        continue;
                   if(resultMap.size() > 0 ) {
                        contentData          = (ArrayList)resultMap.get(GeneralUtil.CONTENT_DATA);
                        headerData          = (ArrayList)resultMap.get(GeneralUtil.COL_METADATA);
                        metaData          = (ArrayList)resultMap.get(GeneralUtil.METADATA);
                        rdef = new ReportDefinition();                    
                        raUtilBean.setReportAttributes(rdef, headerData, metaData,reportId, sReportFormat);
                        titleSpan = raUtilBean.findMaxCol(contentData, rdef.getDisplayCols());
                        if("51031".equals(reportId)){                         
                             if(resultMap.get("HIDE_ETA")!=null){
                                  boolean hideETA = ((Boolean)resultMap.get("HIDE_ETA")).booleanValue();                              
                                  formatter.setHideETA(hideETA);
                                  if(hideETA){
                                       titleSpan = titleSpan-1;
                        rdef.setMaxCol(titleSpan);
                        headerString = formatter.constructHeadingForE2E(rdef, headerData);
                        contentString = formatter.constructContentForE2E(rdef, contentData, strTradeDate, sReportFormat);
    %>     
    <html xmlns:o="urn:schemas-microsoft-com:office:office"
         xmlns:x="urn:schemas-microsoft-com:office:excel"
         xmlns="http://www.w3.org/TR/REC-html40">
         <head>
         <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
         <meta name="ProgId" content="Excel.Sheet"/>
         <meta name="Generator" content="Microsoft Excel 9"/>
         <link rel="File-List" href="./Test33_files/filelist.xml"/>
         <link rel="Edit-Time-Data" href="./Test33_files/editdata.mso"/>
         <link rel="OLE-Object-Data" href="./Test33_files/oledata.mso"/>
         <link href="<%=sContextPath %>/llehman.css" rel="stylesheet" type="text/css">
         <link href="<%=sContextPath %>/llcontent.css" rel="stylesheet" type="text/css">
         <style>
         <xsl:comment>
         table
              {mso-displayed-decimal-separator:"\.";
              mso-displayed-thousand-separator:"\,";}
         .style0
              {mso-number-format:General;
              text-align:general;
              vertical-align:bottom;
              white-space:nowrap;
              mso-rotate:0;
              mso-background-source:auto;
              mso-pattern:auto;
              color:windowtext;
              font-size:10.0pt;
              font-weight:400;
              font-style:normal;
              text-decoration:none;
              font-family:Arial;
              mso-generic-font-family:auto;
              mso-font-charset:0;
              border:none;
              mso-protection:locked visible;
              mso-style-name:Normal;
              mso-style-id:0;}
         .xl21
         {mso-style-parent:style0;
         color:black;
         font-size:8.0pt;
         font-family:Arial, sans-serif;
         mso-font-charset:0;
         border-top:.5pt solid silver;
         border-right:.5pt solid silver;
         border-bottom:.5pt solid silver;
         border-left:none;}
         .xl24
              {mso-style-parent:style0;
              mso-number-format:"\#\,\#\#0\.00_\)\;\\\(\#\,\#\#0\.00\\\)";}
         .xl25
              {mso-style-parent:style0;
              mso-number-format:0%;}
         .xl26
              {mso-style-parent:style0;
              mso-number-format:"\#\,\#\#0_\)\;\\\(\#\,\#\#0\\\)";}
         .xl27
         {mso-style-parent:style0;
         background-color:#666666;
         color:#FFFFFF;
         font-size:9.0pt;     
         font-family:Arial, sans-serif;
         mso-font-charset:0;
         text-align:left;
         vertical-align:middle;
         border-top:none;
         border-right:.5 pt solid silver;
         border-bottom:.5pt  silver;
         border-left:none;
         mso-pattern:auto none;
         white-space:normal;
         .xl55
         color:black;
         font-size:8.0pt;
         font-weight:700;
         mso-style-parent:style0;
         mso-number-format:"\#\,\#\#0_\)\;\[Red\]\\\(\#\,\#\#0\\\)";
         mso-pattern:auto none;
         font-size:9.0pt;
         font-family:Arial, sans-serif;
         mso-font-charset:0;
         text-align:right;
         border-top:none;
         border-right:.5pt solid silver;
         border-bottom:.5pt solid silver;
         border-left:none;
         .xlDate{
         mso-style-parent:style0;
         mso-number-format:"yyyy\\-mm\\-dd";
         .xlDateTime{
         mso-style-parent:style0;
         mso-number-format:"yyyy\\-mm\\-dd\\ h\\:mm\\ AM\/PM";
         </xsl:comment>
         </style>
         <xml>
          <x:ExcelWorkbook>
           <x:ExcelWorksheets>
            <x:ExcelWorksheet>
              <x:Name><%=subtab1%></x:Name>
              <x:WorksheetOptions>
               <x:ProtectContents>False</x:ProtectContents>
               <x:ProtectObjects>False</x:ProtectObjects>
               <x:ProtectScenarios>False</x:ProtectScenarios>
              </x:WorksheetOptions>
            </x:ExcelWorksheet>
           </x:ExcelWorksheets>
          </x:ExcelWorkbook>
          </xml>
         </head>
    <body text="#000000" style="margin-left:5px;margin-top:5px">
          <table border="0" cellpadding="0" cellspacing="0" width="100%">
              <tr>
                  <td>
                       <table  border='0' cellpadding="0"  cellspacing='0' width="100%">
                             <tr class="xl21">
                                  <td align="left" nowrap style='font-size:11px;' colspan="<%=titleSpan%>"><b><%=subtab1%></b> -  COB  <%=irHelper.formatDate(strTradeDate)%>  </td>
                                  </tr>
                         </table>
                   </td>
                </tr>
                <tr>
                     <td> </td>
              </tr>
    <!-- Report Processing -->
              <tr>
                   <td>
                        <%=headerString%>
                        <%=contentString%>
                   </td>
              </tr>
    <%
                   }//end of if
              }//end of while
         }//end of if report_Ids     
    %>          
         </table>
    </body>
    </html>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How do I set the content type ?

    Hi
    I have to upload a file from my Java Application to a remote servlet.
    I have used the HTTPConnection class to connect to the remote servlet and made it call the POST method explicitly.
    How do I set the content type of the file I am uploading from my Java apllication?
    I tried to change the content type in the doPost method. by giving
    req.setContentType("multipart/form-data"); in the doPost.
    It still doesnt work..
    Is there any way to set the content type in the Java application?
    Thanks in advance

    What class is your req variable? If your using a HttpServletRequest, then there is no method req.setContentType("");
    In the HttpServletResponse this is for telling the web browser or receving medium what kind of mime type to expect.
    And what package is the HttpConnection class from?
    I think more precise info is required before this question can be answered.

  • Setting the content type inside the ABAP mapping.

    Hello All,
    Can any one help me by telling me how to set the content-type inside ABAP mapping. I have searched a large no of blogs and help.sap.com for the same.
    My requirement is I want to change the MIME type of the Main Document in side SXMB_MONI so that can change the content type of Main document which is application\xml by default.
    I would appreciate an early response regarding the same.
    Abinash

    Hello Raj,
    The output of my ABAP mapping is a flat file. So when I try to open the file with content type application/xml in the message monitor it shows the file has some error which is natural. The way to get around this problem is change the content type to application\txt from application\xml.
    I am not finding an option to set the content type inside the ABAP mapping for the same.
    Abinash

  • Using Forms that don't set the content type charset

    The Servlet API 2.3 has a new method, request.setCharacterEncoding(), to
              deal with the fact that almost no browsers set the content type. When I call
              this method passing "Shift_JIS" using weblogic 6.1, it works fine when the
              content type is not set by the browser. That is, after calling
              setCharacterEncoding when I call request.getParameter("testparam") I get the
              correct translated value. However, if the content type is
              "application/x-www-form-urlencoded; charset=Shift_JIS" and I call
              request.setCharacterEncoding("Shift_JIS"), getParameter("testparam") returns
              null.
              Can anyone shed some light on this?
              It looks like I'll have to not set the character encoding if it is already
              set. That, of course, opens the possibility that the character set used for
              translation is different than was used in the form.
              Russ Cole
              [email protected]
              

    It might not be the new 3G network. Though I've heard the major metropolitan cities can have slower responses due to congestion.
    Have you upgraded to the new operating system? Have you tried resetting your phone? You can do that by holding the "Home" and "Power" buttons down together, through the shut down screen and until the apple appears on the screen.
    You might also try this:
    http://www.roughlydrafted.com/2010/07/07/how-to-speed-up-your-iphone-3g-running- ios4/
    It's called a cold reboot.
    Sharon

  • SP 2013 Workflow Associations - get the content type for associated tasks with PowerShell

    I am creating a PowerShell script to document SharePoint 2013 workflow associations on a site. I can get the Subscription object for the workflow association, but I can't figure out how to dig into it to find out the Content Type for tasks generated
    by workflows created by this WF association. I can get the Task List ID from the Subscription.PropertyDefinitions, and from there can get the Task List. But the task list may use many different content types, because when you associate a 2013 workflow
    to a list, SharePoint adds the workflow's content type to the set of content types used by the workflow task list. If you have a lot of workflows that use the same task list, that task list gets a lot of content types.
    I have the Subscription object for the workflow association. How can I divine the content type for tasks that the workflow will generate?
    Leigh Webber

    I would suggest you to consider using the SPListItem that running the workflow instance to check the task content type.
    First, find the list item that associated with the workflow, then SPListItem.Tasks returns a collection of workflow tasks for the item, you can check the content type from the task item.
    Qiao Wei
    TechNet Community Support

  • Save Dialog in Office Application does not set the Content Type to the one selected on Document Creation.

    We have a Library that supports 4 Content Types  ("Content Type 1","Content Type 2","Content Type 3","Content Type 4")
    The user clicks new and selects "Content Type 3"
    Word is started
    The user edits the document
    Clicks Save
    "Choose Content Type" dialog is shown set to the Content Type "Content Type 1" because the Document content type is ordered as First (which also means Default)
    What is expected is the "Choose Content Type" dialog to show "Content Type 3" as selected
    Any ideas?

    Hi,
    According to your description, there is a library with four content types, you create a document with one of the content types, click save button in Office application,
    then a “Choose Content Type” dialog will show up for selecting a content type.
    I tried to reproduce as below:
    1. Create a library with four content types;
    2. In the ribbon of this library, “FILES”->”New Document”->”Content Type 1”, then the Office application with the predefined template will be opened for editing;
    3. Click the “Save” button, choose the save path as the current library, click “OK” to finish the process;
    4. Refresh the library in browser, the newly created document appears there.
    In my test, there is no “Choose Content Type” dialog showing up when save the document in Office application.
    I would suggest you provide more details about how to reproduce this issue(screenshot would be better) for further research.
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
    contact [email protected]
    Patrick Liang
    TechNet Community Support

  • How do I set the mime type for an attachment to "application/zip"

    I'm sending out an email with a zip file as an attachment. The following code works fine, but the Mimetype for the attachment is set to "application/octet-stream"
    FileDataSource fds = new FileDataSource(zipname);
    DataHandler dh = new DataHandler(fds);
    MimeBodyPart mbp2 = new MimeBodyPart();
    mbp2.setDataHandler(dh);
    mbp2.setFileName(fds.getName());
    I would like the mime type to be application/x-zip. Unfortunately I seem to need a data content handler for this mime type as I get this exception.
    javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/x-zip
    Building a date content handler in the activation framework seems like a lot of work to do a very simple thing. Am I missing something obvious? Is there a simple way to do this?

    I found the solution after much chasing around. The default mimetypes file that comes with the activation framework does not list zip.

  • Poor interface with Adobe CS4 and setting the file size for emails

    In frustrations over an unfixed bug in iPhoto (slide shows) in addition to too many limitations, I am trying out Aperture. So far it has been a big disappointment. I like Photoshop (CS4) with layers etc. as well as Adobe Camera Raw, both of which I intend to continue using. The workflow in Aperture appears disappointing (Photoshop) and totally absent (Adobe Camera Raw). It seems like Apple's attempt to capture some of Adobe's market share has has happened on the consumer's expense? Besides disappointing functionality, I have run into a surprising problem: No matter how I set the email photo export preset in preferences, the attachment shows up as a large file when exported to Entourage. The size does not change no matter how I set this preference.
    My 21 years of loyalty and enthusiasm towards Apple has taken some heavy blows lately. With some 15000 photos and 35+ albums in iPhoto, I don't see too many alternatives. Can someone tell me if there is a way around these problems.

    First of all I am not comparing Aperture to Photoshop by expecting the layers function. It is the interface between the two I am questioning. We obviously also have different expectations to Aperture. Mine are solely based on my experiences with iPhoto and what Apple tells me on their website:" Aperture 3 is a professional photography application that lets you refine images, showcase your photography, and manage massive photo libraries. Aperture 3 gives you all the easy-to-use tools you need to import, organize, compare, enhance, and share your photos." I do not find a single sentence stating that it is primarily a "Raw image editor processor" as you are defining it. I was not looking for a new raw editor. I was, however, based on Apple's claims above, expecting a combined advanced editing an photo library application. As such I also expected layers. That is not comparing it to Photoshop. Naturally our views are based on expectations and experiences, and ours are just different, that is all.

  • Export Indd to EPS/JPG and set the file name  for EPS/JPG file

    Hi,
       When I export the INDD to JPG/EPS, I want to set the file name with pageNumber  for JPG/EPS files using javascript.
    For Example
    If I set the file name as EPSFile.eps, after exporting the indd(with 2 pages) to eps
    ,files are generating in the following name EPSFile_1.eps, EPSFile_2.eps.
    but I want to set the file name as EPSFile_001.eps and EPSFile_002.eps using javascript.
    anyone knows please reply for this.
    Regards,
    Mubeen

    Hi,
      I tried the following code.
    var JPGe = new File("Applications/PDF/JPG/file.jp");
    app.activeDocument.exportFile(ExportFormat.jpg, );
    when I use this code ,exported jpg file names are
    file.jpg, file1.jpg,file3.jpg.
    but ,I want the output file names as file_001,file_002,file_003,
    Thanks,
    Mubeen

  • What is the content type for a plain text document.

    Hello :)
    I want to generate a plain text document for the user to either see, or to save to disk directly. What do I out for the setContentType MIME type for this?
    Thanks
    Jeff.

    text/plain
    zakir

  • Content-Type for POST request

    Hi all again,
    I am setting content-type in the header to "text/xml"  yet when I do a POST sap sends as content-type
    "application/x-www-form-urlencoded". Is there something else I need to set to make it post with text/xml ?
      cl_http_client=>create_by_url( EXPORTING url = url
                                               ssl_id = 'ANONYM'
                                     IMPORTING client = http_client ).
    * create HTTP client object
    *  cl_http_client=>create_by_destination( EXPORTING DESTINATION = 'ZTOLLREQUEST'
    *                                 IMPORTING client = http_client ).
                                                                                    * Set HTTP headers
      http_client->request->set_header_field( name = '~request_method'
      value = 'POST' ).
      http_client->request->set_header_field( name = 'Content-Type'
      value = 'text/xml' ).
    *  http_client->request->set_header_field( name = 'Authorization'
    *  value = auth_string ).
    *  http_client->request->set_header_field( name = 'sap-password'
    *  value = 'ymous' ).
                                                                                    * Set payload
      http_client->request->set_cdata( xml_string ).
                                                                                    * send and receive
      CALL METHOD http_client->send
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2.
    regards
    Allan

    i havent tried this (setting content type) when using create by url . may be try just the create method and then set the remaining part of the url as headers ~request_uri parameter. something like below.
    call method cl_http_client=>create
      exporting
        host          = 'www.webservicex.net'
        service       = '80'
        scheme        = '1'
        proxy_host    =  wf_proxy
        proxy_service =  wf_port
      importing
        client        = http_client.
    http_client->propertytype_logon_popup = http_client->co_disabled.
    wf_user = user .
    wf_password = password .
    call method http_client->authenticate
      exporting
        proxy_authentication = 'X'
        username             = wf_user
        password             = wf_password.
    call method http_client->request->set_header_field
      exporting
        name  = '~request_method'
        value = 'POST'.
    call method http_client->request->set_header_field
      exporting
        name  = '~server_protocol'
        value = 'HTTP/1.1'.
    call method http_client->request->set_header_field
      exporting
        name  = '~request_uri'
        value = '/airport.asmx'.
    Regards
    Raja

  • I just got a new iphone 5c and set the passcode, but for some reason it wont accept what I type. Now the phone says it is disabled.  What do I do?

    I just bought a new iphone 5c
    typed in a passcode
    went back to type the passcode and it's 'invalid
    now the phone is 'disabled
    any ideas how to reset the phone
    thank you

    Tati7 wrote:
    now the phone is 'disabled
    Connect to iTunes on the computer you usually Sync with and Restore
    http://support.apple.com/kb/HT1414
    Make sure you have the Latest Version of iTunes (v11) Installed on your computer
    iTunes free download from www.itunes.com/download

  • Apex_web_service.make_rest_request: Passing parameters and the content type

    Not sure if I am missing something, but should this API be setting the content type (to application/x-www-url-formencoded) when there are values present for the parameters p_parm_name and p_parm_value.
    The example in the docs is to a yahoo API. I'm not sure about that particular one (see: http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_web_service.htm#BABEDJHJ), and I think it requires an appid (yahoo account), so i just went with the example here:
    http://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_php
    If I run the following from a html file on my desktop it works:
    <form method="POST" action="http://query.yahooapis.com/v1/public/yql">
    <input type="hidden" name="q" value="select * from upcoming.events where location='San Francisco' and search_text='dance'"></input>
    <input type="hidden" name="format" value="json"></input>
    <input type="submit"></input>
    </form>That is, it returns a JSON result.
    The raw HTTP data is as follows:
    POST http://query.yahooapis.com/v1/public/yql HTTP/1.1
    Host: query.yahooapis.com
    Connection: keep-alive
    Content-Length: 110
    Cache-Control: max-age=0
    Origin: null
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11
    Content-Type: application/x-www-form-urlencoded
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: en-AU,en;q=0.8,en-US;q=0.6
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
    q=select+fromupcoming.events+where+location%3D%27San+Francisco%27+and+search_text%3D%27dance%27&format=json>
    However, running the following returns nothing: (nothing, as in nothing that depends on the parameters passed in)
    set serveroutput on
    declare
    l_c CLOB;
    begin
      l_c := apex_web_service.make_rest_request(
        p_url => 'http://query.yahooapis.com/v1/public/yql',
        p_http_method => 'POST',
        p_parm_name => apex_util.string_to_table('q:format'),
        p_parm_value => apex_util.string_to_table('select * from upcoming.events where location=''San Francisco'' and search_text=''dance'':json'),
        p_proxy_override => 'http://192.168.1.3:8888');
      dbms_output.put_line(substr(l_c, 1, 4000));
    end;Raw HTTP data:
    POST http://query.yahooapis.com/v1/public/yql HTTP/1.1
    Host: query.yahooapis.com
    Connection: Keep-Alive
    Content-Length: 106
    Connection: close
    q=select+%2A+from+upcoming%2Eevents+where+location%3D'San+Francisco'+and+search_text%3D'dance'&format=json>
    I do note a key difference is that content type isn't being set in the web service API.
    This was just to test a public service. I do note that the above has slighty different request data (percentage encoding on some chars). However, I experienced the same behaviour on a procedure I had written (I can also provide this example test case if you like), which is where I first noticed the issue.
    Using utl_http and setting the content type to application/x-www-url-formencoded, does resolve the issue. However, just thought i'd see the possibility of using the Web service API that is made available.
    Is the example in the docs valid, or am I missing something obvious?
    This is on ApEx 4.1 on the OTN Dev Days VM.
    Thoughts?

    Hi trent,
    I too have had issues with this API , so moved forward with UTL_HTTP API.
    There is something amiss.
    If you change your code to the one below it works.
    SET SERVEROUT ON
    declare
    l_c CLOB;
    l_param varchar2(1000) ;
    begin
    l_param := 'select * from upcoming.events where location=''San Francisco'' '||
            ' and search_text=''dance'''||'&'||'format=json';
    l_c := apex_web_service.make_rest_request(
        p_url => 'http://query.yahooapis.com/v1/public/yql?q='||
            utl_url.escape(l_param)
        ,p_http_method => 'POST'
      dbms_output.put_line(substr(l_c, 1, 4000));
    end;
    /Note the use of UTL_URL.ESCAPE. The call does not work without it.
    I do not use a proxy, so that parameter does not feature in my snippet above.
    Cheers,
    PS: However, the below does not work. So, it appears that the p_parm_name and p_parm_value do not quite work.
    SET SERVEROUT ON;
    declare
    l_c CLOB;
    l_param varchar2(1000) ;
    begin
    l_param := 'select * from upcoming.events where location=''San Francisco'' and search_text=''dance''';
    l_c := apex_web_service.make_rest_request(
        p_url => 'http://query.yahooapis.com/v1/public/yql'
        ,p_http_method => 'POST'
        ,p_parm_name => apex_util.string_to_table('q:format')
        ,p_parm_value => apex_util.string_to_table(utl_url.escape(l_param)||':json')
      dbms_output.put_line(substr(l_c, 1, 4000));
    end;
    / Edited by: Prabodh on Oct 13, 2012 2:04 PM

  • How to set content-type for outbound mail in BCS

    Hey everybody,
    can anybody please give me a hint how to set the content-type for outbound email in ABAP using BCS to send mail.
    By default the content tyoe is set to text/html. I need other.
    Best regards
    Roman

    //add related mutip-part to combine parts
    MimeMultipart multipart = new MimeMultipart("related");
    //attach a pdf
    messageBodyPart = new MimeBodyPart();
    fds = new FileDataSource("h:/something.pdf");
    messageBodyPart.setDataHandler(new DataHandler(fds));
    messageBodyPart.setFileName(fds.getName());
    multipart.addBodyPart(messageBodyPart);
    //add multipart to the message
    message.setContent(multipart);
    //send message
    Transport.send(message);

Maybe you are looking for

  • How to install realplayer plug-in into safari,

    Hi, i'm using safari for window (WinXP), as at IE i could use video download from real-player but can't at safari, how can i install real player plug-in into safari? so safari also can having the same option for video download

  • Where have System Preferences gone???

    After re-installing the operating system, because it was no longer possible to log on to my iMac, suddenly there are no more system preferences. I select "System preferences" in the Apple menu and nothing happens. Any ideas what to do or try to get a

  • Ethernet connection and airport failure

    I'm studying abroad in Madrid, Spain, and I'm having difficulty with my internet access. On campus, the IT director put in the airport location and password, and it won't log on. It says "failure to connect." Other Macs in the building are working fi

  • Java.util.concurrent.ExecutorService question!!!

    HI, I'm working with java.util.concurrent.ExecutorService. I need to know: Is there a possibility to know that all executions are done, that there is nothing to execute????? All ideas are welcome!:) Thanks a lot!:) Best, Aram.

  • Slow Printing with Adobe Reader 8.1.2 on Terminal Service

    When I want to print something on a Terminal Server without admin rights its very slow, when I print with admin rights its fast. Can someone told me where is the problem with the rights? Thanks