首页 \ 问答 \ HTTP 415不支持的媒体类型(HTTP 415 Unsupported Media Type)

HTTP 415不支持的媒体类型(HTTP 415 Unsupported Media Type)

我创建了一个示例Web服务来进行调用。

我正在使用Jersey JAX-RS和Maven。

web.xml中

<servlet>
    <servlet-name>provider-serlvet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>org.is.ws.provider.rest.ProviderAggregateApplication</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
         </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>provider-serlvet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

的pom.xml

<!-- Jersey jars -->

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19</version>
    </dependency> 
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19</version>
    </dependency>           
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.19</version>
    </dependency>
      <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.18</version>
      </dependency>
      <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>

方法调用:

@POST
@Path(RESOURCE_PATH)
@Produces("text/plain")
public String getPCP(){
    return "Hello";
}

原始要求:

 POST http://localhost:9080/sep/pas/getPCP HTTP/1.1
 Connection: close
 Accept-Encoding: gzip,deflate
 Content-Type: application/json
 Content-Length: 69
 Host: localhost:9080
 User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

  {
    "patientID": "1234567890",
    "patientIDType": "XYZ"
  }

我已经提到了以下文章

REST Webservice返回415 - 不支持的媒体类型

但我仍然有问题。


I have created a sample web service to make a post call.

I am using Jersey JAX-RS, and Maven.

web.xml

<servlet>
    <servlet-name>provider-serlvet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>org.is.ws.provider.rest.ProviderAggregateApplication</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
         </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>provider-serlvet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

POM.XML

<!-- Jersey jars -->

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19</version>
    </dependency> 
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19</version>
    </dependency>           
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.19</version>
    </dependency>
      <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.18</version>
      </dependency>
      <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>

Method call:

@POST
@Path(RESOURCE_PATH)
@Produces("text/plain")
public String getPCP(){
    return "Hello";
}

Raw request:

 POST http://localhost:9080/sep/pas/getPCP HTTP/1.1
 Connection: close
 Accept-Encoding: gzip,deflate
 Content-Type: application/json
 Content-Length: 69
 Host: localhost:9080
 User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

  {
    "patientID": "1234567890",
    "patientIDType": "XYZ"
  }

I have referred to following article

REST Webservice returning 415 - Unsupported Media Type

But still i'm having issue.


原文:https://stackoverflow.com/questions/30825375
更新时间:2022-03-05 21:03

最满意答案

尝试这个:

Sub GetData()

  Dim strPath As String
  Dim strFileName As String
  Dim strFileExtension As String
  Dim strFullName As String

  dim objExcel As Object, objWorkbook As Object
  strPath = "file path here"
  strFileName = "file name here"
  strFileExtension = "Extension here"
  strFullName = strPath & strFileName & strFileExtension

  Set objExcel = CreateObject("Excel.Application")
  Set objWorkbook = objExcel.Workbooks.Open(strFullName)

  'Set the text of the cell from Excel to the cell in the specified table in 
  'Word (the second table in this instance)   

  ActiveDocument.Tables(1).Cell(2, 2).Range.Text =  objWorkbook.Sheets("Sheet1").Cells(2, 1)

  'Close Excel bits

  objWorkbook.Close
  objExcel.Quit
  Set objWorkbook = Nothing
  Set objExcel = Nothing



End Sub

顺便说一下,如果使用上面使用的CreateObject函数,则不需要添加引用。

你有几个问题:

  1. 没有定义(设置) objExcel应用程序
  2. 正确执行后没有关闭(清理)
  3. Excel对象的不必要的公共声明

Try this:

Sub GetData()

  Dim strPath As String
  Dim strFileName As String
  Dim strFileExtension As String
  Dim strFullName As String

  dim objExcel As Object, objWorkbook As Object
  strPath = "file path here"
  strFileName = "file name here"
  strFileExtension = "Extension here"
  strFullName = strPath & strFileName & strFileExtension

  Set objExcel = CreateObject("Excel.Application")
  Set objWorkbook = objExcel.Workbooks.Open(strFullName)

  'Set the text of the cell from Excel to the cell in the specified table in 
  'Word (the second table in this instance)   

  ActiveDocument.Tables(1).Cell(2, 2).Range.Text =  objWorkbook.Sheets("Sheet1").Cells(2, 1)

  'Close Excel bits

  objWorkbook.Close
  objExcel.Quit
  Set objWorkbook = Nothing
  Set objExcel = Nothing



End Sub

Btw you don't need to add references if you use the CreateObject function as used above.

You had a couple of issues:

  1. Did not define (set) the objExcel application
  2. Weren't closing (cleaning) after execution properly
  3. Unnecessary Public declarations of Excel objects

相关问答

更多
  • Sub RemoveFooterRows(theFile) Dim found As Range Set found = Workbooks(theFile).Worksheets(1).Columns(1).Find _ ("Summary", Range("A1"), xlValues, xlPart, xlByRows, xlNext, False, , False) MsgBox ("val is " & found.Row) End Sub 您需要“ ...
  • 出现错误91,因为没有设置对象,所以我会确保ActiveWorkbook确实添加了工作表。 您可能想尝试一下,看看它是否仍然会抛出错误。 Sub Worksheet_UnLock() Dim s as Worksheet For Each s In ActiveWorkbook.Sheets s.Unprotect Password:=myPassword Next End Sub Error 91 occurs because an object is not ...
  • 您可以将If Not IsEmpty(Table1.UsedRange) Then语句添加到代码中。 如果工作表完全为空,这将阻止代码运行。 如果您需要更多帮助,请发表评论。 Sub CreateBasicWordReport() 'Create word doc automatically Dim wApp As Word.Application Dim SaveName As String Set wApp = New Word.Application With wApp 'Make word v ...
  • 这样做你想要的,但你需要优化初始范围选择,以确保你没有拿起任何空值。 Sub SiteAccess() Dim mySheet As Worksheet, myOtherSheet As Worksheet, myBook As Workbook 'Define your workbooks and worksheets as variables Set myBook = Excel.ActiveWorkbook Set mySheet = myBook.Sheets("SiteAccessRepo ...
  • 这是一个直接告诉你行号的函数。 这与您在构建函数中使用以获得最大值然后再次找到它的方法相反! Function GetMaxRow(ByRef myRange As Range) As Long Dim aCell As Range Dim maxVal As Double Dim maxRow As Long maxVal = Application.WorksheetFunction.Min(myRange) maxRow = 0 For Each ...
  • 尝试这个: Sub GetData() Dim strPath As String Dim strFileName As String Dim strFileExtension As String Dim strFullName As String dim objExcel As Object, objWorkbook As Object strPath = "file path here" strFileName = "file name here" strFileEx ...
  • 似乎Selection随时无效,即在运行宏时,选择以某种方式无效,例如通过用户点击Excel窗口或类似的东西。 尝试直接使用图形或对象的Left属性,而不使用Selection. : x = 1 While x < 4 With wb.Sheets("SheetX").ChartObjects(x) .Parent.Height = 500 ' resize .Parent.Width = 1200 ' resize .Parent.Top = 100 ...
  • 如果新表不包含任何数据,则其DataBodyRange为Nothing。 向表中添加任何数据时,DataBodyRange设置为一个范围,即使稍后删除数据,它也将保持初始化状态。 在您的情况下,最简单的解决方案可能是在执行任何操作之前测试DataBodyRange,即 If Not sht.ListObjects("Basic_Data_Table").DataBodyRange Is Nothing Then your code here End if 要么 If sht.ListObjects ...
  • 不确定为什么将'BuildSel'改为variant会使它工作,但是当没有找到匹配的列表项时,它所代表的代码没有错误检查 以下代码应该更适合使用: Private Sub BuildList_Click() Dim Ref As Worksheet: Set Ref = ThisWorkbook.Sheets("Ref") Dim BuildSel As Range With Ref Set BuildSel = .Range("B2", .Range("B" & R ...
  • 你在sub中做的第一件事是你清空刚刚通过的Argument(使用Set rs = Nothing ),然后再次使用rs 。 所以除非rs是一个类似Public的变量并且它填充了ConnectToDb , 在使用之前它仍然是空的,错误! 首先,尝试删除Set rs = Nothing ,如果还不够,您需要查看ConnectToDb ! 其次,你修改了sub中的Recordset,但你试着在外面使用它。 这里的问题是使用ByVal ,它传递了Object的引用副本,所以你不能修改初始对象,因为RecordSet ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)