Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a API call that works with C# but when ported to VB.net is returns a
"Cannot send a content-body with this verb-type."

in the response.content

This same exact call works with C# in with no problem. Is it a UTF encoding issue? I notice the payload in c# is UTF16 encoded but in VB its UTF8.

Can anyone provide a simple request package/example for POST of a REST API that works in VB as the app im chaning is written in VB.NET

What I have tried:

VB.NET
VB
'call resume parser API https://rapidapi.com/pathx-pathx-default/api/skill-extraction/

Dim payload1 As Object = New Dictionary(Of Object, Object) From {
    {"operation", "text_extraction"},
    {"text", "You will be responsible for the development of server-side logic, definition and maintenance of databases, and ensuring high performance and responsiveness to requests from the front-end. Additionally, you will be developing user interface components and implementing them following well-known workflows for whatever languages and frameworks are in use. You will ensure that these components and the overall application are robust and easy to maintain. You are expected to coordinate with your team, working on different layers of the infrastructure. Therefore, a commitment to collaborative problem solving, sophisticated design, and quality products is important."}
}

Dim client = New RestClient("https://skill-extraction.p.rapidapi.com/skill_extraction")
Dim request As RestRequest = New RestRequest(Method.Post)
request.AddHeader("content-type", "application/json")
request.AddHeader("X-RapidAPI-Key", "##############################")
request.AddHeader("X-RapidAPI-Host", "skill-extraction.p.rapidapi.com")
'request.AddParameter("application/json", strOutput, ParameterType.RequestBody)
request.AddParameter("application/json", payload1, ParameterType.RequestBody)
' Dim result As IRestResponse = client.Execute(request)
Dim response As RestResponse = client.Execute(request)

ASPxLabel1.Text = response.Content



C#
C#
namespace sharptest
{
    public partial class jsontest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var client = new RestClient("https://skill-extraction.p.rapidapi.com/skill_extraction");
            var request = new RestRequest(Method.POST);
            request.AddHeader("content-type", "application/json");
            request.AddHeader("X-RapidAPI-Key", "###########################");
            request.AddHeader("X-RapidAPI-Host", "skill-extraction.p.rapidapi.com");
            request.AddParameter("application/json", "{\r\n    \"operation\": \"text_extraction\",\r\n    \"text\": \"Chief Technology Officer Profile Visionary leader with a distinguished history of building\"\r\n}", ParameterType.RequestBody);
            RestResponse response = (RestResponse)client.Execute(request);
            Label1.Text = response.Content.ToString();
        }
    }
}
Posted
Updated 24-Jan-23 7:43am
v3
Comments
0x01AA 24-Jan-23 3:22am    
'This same exact call works with C# in with no problem': Payload is completely different.
What is, if you use exactly same payload in VB which you are using in c#?

Holy cow who would have thought it was that sensitive but apprently by using the integer version for POST it worked!!!

VB
Dim client = New RestClient("https://skill-extraction.p.rapidapi.com/skill_extraction")
       Dim request As RestRequest = New RestRequest
       request.Method = 1
       request.AddHeader("content-type", "application/json")
       request.AddHeader("X-RapidAPI-Key", "c92bc820damshdc50cac3ff03c0fp1caee3jsna52493ef14fa")
       request.AddHeader("X-RapidAPI-Host", "skill-extraction.p.rapidapi.com")
       'request.AddParameter("application/json", strOutput, ParameterType.RequestBody)
       request.AddParameter("application/json", payload1, ParameterType.RequestBody)
       ' Dim result As IRestResponse = client.Execute(request)
       Dim response As RestResponse = client.Execute(request)

       ASPxLabel1.Text = response.Content
 
Share this answer
 
v2
Your "verb-type" case is different between the two versions:

* VB you have "Method.Post"
* C# you have "Method.POST"

That is all that I can see...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900