From 7.32 to 7.33

Upload data

In JxBrowser 7.33, we have removed a method to configure the upload data in LoadUrlParams as a raw text.

7.32 and earlier:

With an old API, the type of the data was undefined, and it was up to a web server to interpret this data.

import com.teamdev.jxbrowser.navigation.LoadUrlParams;
...
LoadUrlParams params =
    LoadUrlParams.newBuilder("https://example.com")
        .postData("foo=bar&buzz=feed")
        .build();
browser.navigation().loadUrl(params);
import com.teamdev.jxbrowser.navigation.LoadUrlParams
...
val params = 
    LoadUrlParams.newBuilder("https://example.com")
        .postData("foo=bar&buzz=feed")
        .build()
browser.navigation().loadUrl(params)

7.33:

With the new API, every type of upload data must have a type:

import com.teamdev.jxbrowser.navigation.LoadUrlParams;
import com.teamdev.jxbrowser.net.FormData;
import com.teamdev.jxbrowser.net.FormData.Pair;
...
FormData formData =
    FormData.newBuilder()
        .addPair(Pair.of("foo", "bar"))
        .addPair(Pair.of("buzz", "feed"))
        .build();
LoadUrlParams params =
    LoadUrlParams.newBuilder("https://example.com")
        .uploadData(formData)
        .build();
browser.navigation().loadUrl(params);
import com.teamdev.jxbrowser.navigation.LoadUrlParams
import com.teamdev.jxbrowser.net.FormData
import com.teamdev.jxbrowser.net.FormData.Pair
...
val formData =
    FormData.newBuilder()
        .addPair(Pair.of("foo", "bar"))
        .addPair(Pair.of("buzz", "feed"))
        .build()
val params =
    LoadUrlParams.newBuilder("https://example.com")
        .uploadData(formData)
        .build()
browser.navigation().loadUrl(params)

Alternatively, you can use an arbitrary format of upload data by using ByteData with the custom content type.

import com.teamdev.jxbrowser.navigation.LoadUrlParams;
import com.teamdev.jxbrowser.net.ByteData;
import com.teamdev.jxbrowser.net.ContentType;
...
ContentType type = ContentType.newBuilder("application/x-www-form-urlencoded").build();
ByteData byteData = ByteData.of("foo=bar&buzz=feed".getBytes(UTF_8), type);
LoadUrlParams params =
        LoadUrlParams.newBuilder("https://example.com")
                .uploadData(byteData)
                .build();
browser.navigation().loadUrl(params);
import com.teamdev.jxbrowser.navigation.LoadUrlParams
import com.teamdev.jxbrowser.net.ByteData
import com.teamdev.jxbrowser.net.ContentType
...
val type = ContentType.newBuilder("application/x-www-form-urlencoded").build()
val byteData = ByteData.of("foo=bar&buzz=feed".toByteArray(), type)
val params =
    LoadUrlParams.newBuilder("https://example.com")
        .uploadData(byteData)
        .build()
browser.navigation().loadUrl(params)
Go top