Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:13:08+00:00 2026-06-03T08:13:08+00:00

I upgraded from async_sinatra 0.5.0 to 1.0 because the latter fixed this problem So

  • 0

I upgraded from async_sinatra 0.5.0 to 1.0 because the latter fixed this problem

So far so good. But when I went back to my original app, (as opposed to my test app), which contained authentication, it stopped working. I am using vb.net to make a webrequest, and this worked fine under 0.5.0, but now fails with

"The remote server returned an error: (401) Unauthorized."

Here is my ruby code:

#gem  'async_sinatra', '0.5.0'
require 'sinatra/async'

class AsyncQueryServer < Sinatra::Base
  register Sinatra::Async

  set :server, 'thin'
  set :port, 19876
  enable :show_exceptions

  helpers do
    def protected!
      unless authorized?
        response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
        throw(:halt, [401, "Not authorized\n"])
      end
    end

    def authorized?
      @auth ||=  Rack::Auth::Basic::Request.new(request.env)
      begin
        puts "@auth.provided? #{@auth.provided?}"
        puts "@auth.basic? #{@auth.basic?}"
        puts "@auth.credentials #{@auth.credentials}"
      rescue Exception => e
        puts e.message
      end
      @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['myusername', 'mypassword']
    end
  end

  apost '/execfqy' do
    protected!
    body request.body.string
  end

  not_found do
    puts "in not found, request.fullpath #{request.fullpath}"
    puts "in not found, request.request_method #{request.request_method}"
    puts "in not found, request.params #{request.params}"
    puts "in not found, request.class #{request.class}"

    redirect '/'
  end

end

AsyncQueryServer.run!

I am sure it is the upgrade to async_sinatra 1.0, because if I uncomment

#gem  'async_sinatra', '0.5.0'

it works as expected.

Interestingly, the output for the puts statements in authorized? is the same for both versions, and shows:

@auth.provided? false 
undefined method `split' for nil:NilClass
@auth.provided? true 
@auth.basic? true 
@auth.credentials ["myusername", "mypassword"]

And here is the snippet from vb.net, based on this page, which makes the webrequest:

Private Function GetOutput(jsonDataBytes As Byte()) As String
        Dim req As WebRequest
        Dim res As String
        '        Dim cred As New Net.NetworkCredential("myusername", "mypassword")
        Dim cred As New Net.NetworkCredential("myusername", "mypassword")
        Dim req_str As String

        req_str = _urlString & ":" & _portString & "/execfqy"

        req = WebRequest.Create(req_str)

        req.ContentType = "application/json"
        req.Method = "POST"
        req.ContentLength = jsonDataBytes.Length
        req.Credentials = cred

        Dim stream = req.GetRequestStream()
        stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
        stream.Close()

        Try
            Dim response = req.GetResponse().GetResponseStream()
            Dim reader As New StreamReader(response)
            res = reader.ReadToEnd()
            reader.Close()
            response.Close()
        Catch e As WebException
            Throw New NoResultsError("Request return nil results with error: " & e.Message)
            res = Nothing
        End Try

        Return res
End Function 

Any help/suggestions/redirections would be most appreciated.

TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:13:10+00:00Added an answer on June 3, 2026 at 8:13 am

    Here’s how I fixed it: I abandoned the vb.net native method, and used chilkat’s http component. Works great. Here’s the code:

    Private Function GetOutputChilkatPostJson(jsonData As String) As String
        'Dim req As New Chilkat.HttpRequest()
        Dim http As New Chilkat.Http()
        Dim res As String
        Dim req_str As String
        Dim success As Boolean
    
        req_str = _urlString & ":" & _portString & "/execfqy"
    
        '  Any string unlocks the component for the 1st 30 days.
        success = http.UnlockComponent("Anything for 30-day trial")
        If (success <> True) Then
            MsgBox(http.LastErrorText)
            Exit Function
        End If
    
    
        '  This example duplicates the HTTP POST shown at
        '  http://json.org/JSONRequest.html
    
        '  Specifically, the request to be sent looks like this:
        '  
        'POST /request HTTP/1.1
        'Accept: application/jsonrequest
        '        Content(-Encoding) : identity()
        'Content-Length: 72
        'Content-Type: application/jsonrequest
        'Host:   json.penzance.org()
    
        '{"user":"doctoravatar@penzance.com","forecast":7,"t":"vlIj","zip":94089}
    
    
        '  First, remove default header fields that would be automatically
        '  sent.  (These headers are harmless, and shouldn't need to
        '  be suppressed, but just in case...)
        http.AcceptCharset = ""
        http.UserAgent = ""
        http.AcceptLanguage = ""
        http.Login = "myusername"
        http.Password = "mypassword"
        '  Suppress the Accept-Encoding header by disallowing
        '  a gzip response:
        http.AllowGzip = False
    
        '  If a Cookie needs to be added, it may be added by calling
        '  AddQuickHeader:
        'http.AddQuickHeader("Cookie", "JSESSIONID=1234")
    
        '  To use SSL/TLS, simply use "https://" in the URL.
    
        '  IMPORTANT: Make sure to change the URL, JSON text,
        '  and other data items to your own values.  The URL used
        '  in this example will not actually work.
    
        Dim resp As Chilkat.HttpResponse
        Try
            resp = http.PostJson(req_str, jsonData)
            res = resp.BodyStr
        Catch e As WebException
            Throw New NoResultsError("Request return nil results with error: " & e.Message)
            res = Nothing
        End Try
        Return res
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I upgraded from MacOS X 10.6 (Snow Leopard) to 10.7 (Lion) this morning, and
I've just upgraded from MRI-1.8.7 to MRI-1.9.1 and heard about this lighthouse ticket which
I just upgraded from Rails 3.0.3 to 3.2.1. The upgrade went smoothly on my
I recently upgraded from Grails 1.3.7 to Grails 2.0.1. The application runs normal, but
I just upgraded from rails 2.3.5 to rails 2.3.8, but now my redirects are
I just upgraded from SQL Server 2008 to SQL Server 2008 R2. I went
We just recently upgraded from VS2008 to VS2010. Our project compiles fine; but when
We've recently upgraded from Visual SourceSafe to SVN based on recommendations on this site.
I just recently upgraded from VS2008 to VS2010. Because I do a lot of
just upgraded from jquery 1.4.2 to 1.4.4 and i've encountered a performance problem which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.