PUT and DELETE methods with Httpstream?

Asked

Viewed 127 times

6

Can anyone tell me if it’s possible to use the HttpStream with the methods PUT and/or DELETE?

HttpStream.Options options = new HttpStream.Options();
options.setCharsetEncoding(HttpStream.Options.CHARSET_UTF8);
options.httpType = HttpStream.GET;
options.setContentType("application/json");

HttpStream httpStream = new HttpStream(new URI(VarGlobais.url), options);

in the HttpStream.Option is only accepted GET and POST. How do I get around it?

I know that the HttpConn has these options of PUT and DELETE, but when using the HttpConn in the WinCE error saying that the Class is not found HttpConn, so today I’m using the HttpStream.

  • The language is Java ?

  • 1

    Yes, it’s Java using the Totalcross platform

1 answer

3


Do Javadoc (my griffin):

The default type is GET.
You can also define a custom type, like if you want to use restful services. In this case, the header will be set to what you store in the httpType String. Note that, to use Another http method, append a space.

Example with the method PUT:

HttpStream.Options options = new HttpStream.Options();
options.httpType = "PUT ";

Example with a CUSTOMMETHOD whichever:

HttpStream.Options options = new HttpStream.Options();
options.httpType = "CUSTOMMETHOD ";

Note the spaces between the end of the method name and the end of the string.

If you have a method that is not described in HttpStream and want to indicate that send data, you need to indicate this in Options:

HttpStream.Options options = new HttpStream.Options();
options.httpType = "PUT ";
options.setSendData(true);

About the HttpConn

The class HttpConn is a container/wrapper about the HttpStream. It provides no more functionality than using the HttpStream pure. It makes life much easier yes, but it is possible to get the same results using the HttpStream.

Class HttpConn undetected?

This class belongs to a library. To import libraries into the project, you need to export them as .tcz and put in the all.pkg the name of the generated file.


UPDATE

Automatic management of dependencies

From Totalcross 4, we have supported the automatic generation of .tczthe intermediaries and their management in the all.pkg. Even this was cited as one of the highlights release version.

In free translation:

  • Want to add your dependencies automatically? Have a look at tc-compiler-help
    • The archive all.pkg is dynamically updated with its dependencies, returning to its initial state at the end of the exection
  • See examples of build:
    • Build for multiple platforms here
    • Must compile with dependencies magical-utils, tc-utilities and tc-components here

To enable the use of tc-compiler-help, the first step is to add dependency to the project:

<dependency>
    <groupId>com.totalcross.utils</groupId>
    <artifactId>tc-compiler-help</artifactId>
    <version>1.1.0</version>
</dependency>

To properly download this dependency, you need to use the Maven repository from Totalcross OR download the project tc-compiler-help on your machine

To actually use the build wizard, you should start by creating an object of the type CompilationBuilder.

The CompilationBuilder meets (almost) the same demands as the tc.Deploy answers. In fact, CompilationBuilder will make calls to tc.Deploy safely/in sandbox. You can set your key, set what is the main class, parameters build others, define platforms, modify the environment variables before the execution of the tc.Deploy freely.

The only cases where the tc.Deploy features that the CompilationBuilder does not answer is to create the tcz or the executable from a .class or a .zip; but that was not defective, was design choice, so we only allowed so create tczand enforceable from .jar.

Almost all configuration methods of CompilationBuilder return the object itself. This allows you to perform method call chaining.

In addition to the traditional configurations of a build in Totalcross, you can define which dependencies they find need to be compiled to generate the executable. To do this, just call setMustCompile with a function that will judge, based on the dependency path, whether it should enter the executable or not.

Internally, the CompilationBuilder passes all elements of the classpath to be judged by the function.

To spin this CompilationBuilder in your project:

  1. create a class with a method public static void main; nesse método, você deve configurar oCompilationbuilderdireta ou indiretamente; vamos chamar essa classe dewith.hello.world.Classecompilacao`;
  2. spin mvn clean package exec:java -Dexec:mainClass="com.hello.world.ClasseCompilacao"
  • 1

    Jefferson, it worked... I had tried to put String, but had not concatenated with the space at the end. And yes, I looked at the javadoc.. But at least here you don’t have this part that says to concatenate space. Could you confirm if this is the same link or if I’m looking at some outdated javadoc? (http://rs.totalcross.com/doc/totalcross/net/HttpStream.Options.html#httpType)

  • @Really, this Javadoc is very outdated. I will try to update to the latest version released

Browser other questions tagged

You are not signed in. Login or sign up in order to post.