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 7983185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:53:21+00:00 2026-06-04T10:53:21+00:00

Since RubyMotion appears to do a lot of type-conversion at compile-time, I’m having trouble

  • 0

Since RubyMotion appears to do a lot of type-conversion at compile-time, I’m having trouble passing in a proper dataType into a NSMutableURLRequest POST request. It’s expecting NSData, but I can’t figure out how to type an NSString variable to NSData without throwing an error. Without typecasting, our SOAP server can’t properly receive the data and I get the dreaded (and vague) “The data at the root level is invalid. Line 1, position 1” error.

This is the problematic line:

postXML = "<xml><whatever>hey</whatever></xml>"
postData = ( postXML as NSData ).dataUsingEncoding( NSUTF8StringEncoding, allowLossyConversion: true );

request = NSMutableURLRequest.alloc.init
request.setURL( NSURL.URLWithString( "https://services.sbx1.cdops.net/v4.3/SubscriberServicePox.svc/Login" ) )
request.setHTTPMethod( "POST" )

request.setValue( "application/xml", forHTTPHeaderField: "Content-Type" )
request.setHTTPBody( postData, dataUsingEncoding:NSUTF8StringEncoding )

theConnection = NSURLConnection.alloc.initWithRequest( request, delegate:self )

Any help would be appreciated.

  • 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-04T10:53:23+00:00Added an answer on June 4, 2026 at 10:53 am

    Your understanding of what is going on has some holes, so let’s break it down.

    postXML = "<xml><whatever>hey</whatever></xml>"
    postData = ( postXML as NSData ).dataUsingEncoding( NSUTF8StringEncoding, allowLossyConversion: true );
    

    I’m not sure where you got ( postXML as NSData ) from but it is not valid and makes no sense. dataUsingEncoding:allowLossyConversion: is an Objective-C method declared on NSString not NSData. The correct way to call it would be like this

    postData = postXML.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
    

    Ruby motion doesn’t do type conversions for you, Ruby does not and Objective-C does not. If you send a message to a instance of a class that does not respond to the message you send it, you will crash/raise an exception.

    When you call

    postXML.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
    

    you are not doing type casting, you are sending the message dataUsingEncoding:allowLossyConversion: to an instance of NSString. This will cause a new completely new object (an instance of NSData) to be returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since I'm very new to jQuery I'm having some troubles with this issue. I'm
Since typeid(T).name() doesn't return human understandable name of the type, it doesn't help us
Since url JavaScript should be injected into the webview, could someone let me know
Since I'm still new to Java, I'm running into some need for clarification how
Since a static function call is translated into a static invocation bytecode regardless of
Since Java doesn't allow passing methods as parameters, what trick do you use to
Since updated to Firefox 12, every time I launch Firefox with a particular profile
Since websql is depreciated so I was looking into IndexedDB for browser offline storage
Since the commands module is deprecated since Python 2.6, I'm looking into the best
Since few weeks we have some trouble with our external test environment (which is

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.